溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

mysql中表數(shù)據(jù)存放路徑非datadir目錄的示例分析

發(fā)布時(shí)間:2021-11-06 17:43:51 來(lái)源:億速云 閱讀:163 作者:柒染 欄目:建站服務(wù)器

mysql中表數(shù)據(jù)存放路徑非datadir目錄的示例分析,針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。

假如,新建一張表,并讓該表的存儲(chǔ)路徑 不是默認(rèn)的/path/to/datadir/dbname 。而是 指定存儲(chǔ)的位置 應(yīng)該如何處理?


方法一
shell> mkdir /Generalt1
shell> chown mysql.mysql /Generalt1
mysql> create table test_ger1 (a int) data directory='/Generalt1';
Query OK, 0 rows affected (0.15 sec)
shell> cd /Generalt1

shell> ll test_ger1* # 在datadir 的 test 目錄下
-rw-r-----. 1 mysql mysql 8554 Jan 3 16:41 test_ger1.frm
-rw-r-----. 1 mysql mysql 36 Jan 3 16:41 test_ger1.isl # 這是鏈接文件,鏈接到上面的ibd文件
shell> cat test_ger1.isl # 一個(gè)文本文件,內(nèi)容就是idb文件的路徑
/Generalt1/test/test_ger1.ibd


方法二
在mysql 5.7之后,可以使用`通用表空間`

語(yǔ)法:
CREATE TABLESPACE tablespace_name ADD DATAFILE 'file_name' [FILE_BLOCK_SIZE = value] [ENGINE [=] engine_name]

-- 1: 創(chuàng)建一個(gè)通用表空間
mysql> create tablespace ger_space add datafile '/Generalt1/ger_space.ibd' file_block_size=8192;
Query OK, 0 rows affected (0.07 sec)
-- datafile 指定存儲(chǔ)路徑后,在datadir下會(huì)產(chǎn)生一個(gè)isl文件,該文件的內(nèi)容為General space的ibd文件的路徑
-- 如果datafile不指定路徑,則ibd文件默認(rèn)存儲(chǔ)在datadir目錄下,且不需要isl文件了

mysql> create tablespace ger_space2 add datafile 'ger_space2.ibd' file_block_size=8192;
Query OK, 0 rows affected (0.06 sec)
shell> ll ger*
-rw-r-----. 1 mysql mysql 32768 Jan 3 16:51 ger_space2.ibd # 未指定路徑,存放于datadir目錄
-rw-r-----. 1 mysql mysql 26 Jan 3 16:50 ger_space.isl # 指定了其他路徑,存在isl鏈接文件

shell> cat ger_space.isl
/Generalt1/ger_space.ibd # ibd文件真實(shí)存在的路徑

mysql> select * from information_schema.innodb_sys_tablespaces where name='ger_space'\G
*************************** 1. row ***************************
SPACE: 96
NAME: ger_space
FLAG: 2304
FILE_FORMAT: Any
ROW_FORMAT: Any
PAGE_SIZE: 8192 -- page_size是8k
ZIP_PAGE_SIZE: 0
SPACE_TYPE: General -- General類型
FS_BLOCK_SIZE: 0
FILE_SIZE: 18446744073709551615
ALLOCATED_SIZE: 2
COMPRESSION: None
1 row in set (0.00 sec)

-- 2: 創(chuàng)建表
mysql> create table test_ger2 (a int) tablespace=ger_space;
Query OK, 0 rows affected (0.11 sec)

shell> ll test_ger* # 在datadir 的 test 目錄下
-rw-r-----. 1 mysql mysql 8554 Jan 3 16:41 test_ger1.frm
-rw-r-----. 1 mysql mysql 36 Jan 3 16:41 test_ger1.isl
-rw-r-----. 1 mysql mysql 8554 Jan 3 17:09 test_ger2.frm # 僅有一個(gè)frm文件

shell> ll /Generalt1/
total 52
drwxr-x---. 2 mysql mysql 4096 Jan 3 16:41 test
-rw-r-----. 1 mysql mysql 49152 Jan 3 17:09 ger_space.ibd # test_ger2的ibd文件其實(shí)存儲(chǔ)在ger_space.ibd的通用表空間中

mysql> create table test_ger3 (a int) tablespace=ger_space; -- test_ger3 也存放在ger_space.ibd中
Query OK, 0 rows affected (0.09 sec)

關(guān)于mysql中表數(shù)據(jù)存放路徑非datadir目錄的示例分析問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI