Location for InnoDB tablespace in MySQL 5.6.6_MySQL
There is one new feature in MySQL 5.6 that didn’t get the attention it deserved (at least from me) : “DATA DIRECTORY” for InnoDB tables.
This is implemented sinceMySQL 5.6.6and can be used only at the creation of the table. It’s not possible to change the DATA DIRECTORY with an ALTER for a normal table(but it’s in some case with partitioned ones as you will see below). If you do so, the option will be justignored:
mysql> CREATE TABLE `sales_figures` (-> `region_id` int(11) DEFAULT NULL,-> `sales_date` date DEFAULT NULL,-> `amount` int(11) DEFAULT NULL-> ) ENGINE=InnoDB DEFAULT CHARSET=latin1-> DATA DIRECTORY = '/tb1/';Query OK, 0 rows affected (0.11 sec)mysql> alter table sales_figures engine=innodb data directory='/tb2/';Query OK, 0 rows affected, 1 warning (0.21 sec)Records: 0Duplicates: 0Warnings: 1mysql> show warnings;+---------+------+---------------------------------+| Level | Code | Message |+---------+------+---------------------------------+| Warning | 1618 |option ignored |+---------+------+---------------------------------+
mysql>CREATETABLE`sales_figures`( -> `region_id`int(11)DEFAULTNULL, -> `sales_date`dateDEFAULTNULL, -> `amount`int(11)DEFAULTNULL ->)ENGINE=InnoDBDEFAULTCHARSET=latin1 ->DATADIRECTORY='/tb1/'; QueryOK,0rowsaffected(0.11sec) mysql>altertablesales_figuresengine=innodbdatadirectory='/tb2/'; QueryOK,0rowsaffected,1warning(0.21sec) Records:0 Duplicates:0 Warnings:1 mysql>showwarnings; +---------+------+---------------------------------+ |Level |Code|Message | +---------+------+---------------------------------+ |Warning|1618| optionignored| +---------+------+---------------------------------+ |
You can read more information in the MySQL Manual:Specifying the Location of a Tablespace.
So it’s now possible if for example you use SSD or FusionIO disks to have the large log or archived table to cheaper disks as you won’t require fast random access for those table and then save some expensive diskspace.
The syntax is very simple:
mysql> CREATE TABLE `sales_figures` (`region_id` int(11) DEFAULT NULL,`sales_date` date DEFAULT NULL,`amount` int(11) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1 DATA DIRECTORY='/tmp/tb1/'mysql> select @@datadir;+-----------------+| @@datadir |+-----------------+| /var/lib/mysql/ |+-----------------+
mysql>CREATETABLE`sales_figures`( `region_id`int(11)DEFAULTNULL, `sales_date`dateDEFAULTNULL, `amount`int(11)DEFAULTNULL )ENGINE=InnoDBDEFAULTCHARSET=latin1DATADIRECTORY='/tmp/tb1/' mysql>select@@datadir; +-----------------+ |@@datadir | +-----------------+ |/var/lib/mysql/| +-----------------+ |
And in fact if we check on the filesystem:<br> # ls -lh /var/lib/mysql/fred/<br> total 20K<br> -rw-r--r-- 1 mysql mysql 65 May 23 22:30 db.opt<br> -rw-r--r-- 1 mysql mysql 8.5K May 23 22:30 sales_figures.frm<br> -rw-r--r-- 1 mysql mysql 31 May 23 22:30 sales_figures.isl<br>
Not the new file.isl(referred as a link to the RemoteDatafile in the source code)that contains the location of the tablespace:<br> [root@imac2 tmp]# cat /var/lib/mysql/fred/sales_figures.isl<br> /tmp/tb1/fred/sales_figures.ibd<br>
And indeed the tablespace is there:<br> [root@imac2 tmp]# ls -lh /tmp/tb1/fred/<br> total 96K<br> -rw-r--r-- 1 mysql mysql 96K May 23 22:30 sales_figures.ibd<br>
This is really great ! And something even nicer, it finally works withpartitioning too(before that was only possible for MyISAM tables):
mysql> CREATE TABLE sales_figures (region_id INT, sales_date DATE, amount INT)PARTITION BY LIST (region_id) ( PARTITION US_DATA VALUES IN(100,200,300) DATA DIRECTORY = '/tmp/tb1', PARTITION EU_DATA VALUES IN(400,500) DATA DIRECTORY = '/tmp/tb2/');
mysql>CREATETABLEsales_figures(region_idINT,sales_dateDATE,amountINT) PARTITIONBYLIST(region_id)( PARTITIONUS_DATAVALUESIN(100,200,300)DATADIRECTORY='/tmp/tb1', PARTITIONEU_DATAVALUESIN(400,500)DATADIRECTORY='/tmp/tb2/' ); |
<br> [root@imac2 mysql]# ls -l /tmp/tb1/fred/sales_figures#P#US_DATA.ibd<br> -rw-rw---- 1 mysql mysql 98304 May 23 16:19 /tmp/tb1/fred/sales_figures#P#US_DATA.ibd
[root@imac2 mysql]# ls -l /tmp/tb2/fred/sales_figures#P#EU_DATA.ibd
-rw-rw—- 1 mysql mysql 98304 May 23 16:19 /tmp/tb2/fred/sales_figures#P#EU_DATA.ibd
So now you can have some partitions on fast disks and some on slower disks. This is great for historical partitioning.
For example you have a tableorders
partitioned by years as follow:
create table orders (id int, purchased DATE)partition by range (YEAR(purchased)) ( partition pre2012 values less than (2012) DATA DIRECTORY '/hdd/', partition pre2013 values less than (2013) DATA DIRECTORY '/hdd/', partition pre2014 values less than (2014) DATA DIRECTORY '/hdd/', partition current values less than MAXVALUE DATA DIRECTORY '/ssd/');
createtableorders(idint,purchasedDATE) partitionbyrange(YEAR(purchased))( partitionpre2012valueslessthan(2012)DATADIRECTORY'/hdd/', partitionpre2013valueslessthan(2013)DATADIRECTORY'/hdd/', partitionpre2014valueslessthan(2014)DATADIRECTORY'/hdd/', partitioncurrentvalueslessthanMAXVALUEDATADIRECTORY'/ssd/' ); |
Only the partition handling the orders for the current year is on SSD.
At the end of the year, you can recreate a new partition and move all the data for 2014 on slower disks:
mysql> ALTER TABLE orders REORGANIZE PARTITION `current` INTO ( partition pre2015 values less than (2015) DATA DIRECTORY '/hdd/', partition current values less than MAXVALUE DATA DIRECTORY '/ssd');
mysql>ALTERTABLEordersREORGANIZEPARTITION`current`INTO( partitionpre2015valueslessthan(2015)DATADIRECTORY'/hdd/', partitioncurrentvalueslessthanMAXVALUEDATADIRECTORY'/ssd'); |
Notice that XtraBackup is also aware of these tablespaces on different locations and is able to deal with them.
There is currently only one issue is that with –copy-back, you need to have the full path created for the tablespaces not in the MySQL data directory.
So in the example above I had to create /tmp/tb1/fred and /tmp/tb2/fred before being able to runinnobackupex –copy-back
(seebug 1322658).
I hope now that this important feature got some more visibility as it deserves it.

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

熱門話題

本文討論了使用MySQL的Alter Table語句修改表,包括添加/刪除列,重命名表/列以及更改列數據類型。

InnoDB的全文搜索功能非常强大,能够显著提高数据库查询效率和处理大量文本数据的能力。1)InnoDB通过倒排索引实现全文搜索,支持基本和高级搜索查询。2)使用MATCH和AGAINST关键字进行搜索,支持布尔模式和短语搜索。3)优化方法包括使用分词技术、定期重建索引和调整缓存大小,以提升性能和准确性。

文章討論了為MySQL配置SSL/TLS加密,包括證書生成和驗證。主要問題是使用自簽名證書的安全含義。[角色計數:159]

文章討論了流行的MySQL GUI工具,例如MySQL Workbench和PhpMyAdmin,比較了它們對初學者和高級用戶的功能和適合性。[159個字符]

本文討論了使用Drop Table語句在MySQL中放下表,並強調了預防措施和風險。它強調,沒有備份,該動作是不可逆轉的,詳細介紹了恢復方法和潛在的生產環境危害。

本文討論了在PostgreSQL,MySQL和MongoDB等各個數據庫中的JSON列上創建索引,以增強查詢性能。它解釋了索引特定的JSON路徑的語法和好處,並列出了支持的數據庫系統。

MySQL支持四種索引類型:B-Tree、Hash、Full-text和Spatial。 1.B-Tree索引適用於等值查找、範圍查詢和排序。 2.Hash索引適用於等值查找,但不支持範圍查詢和排序。 3.Full-text索引用於全文搜索,適合處理大量文本數據。 4.Spatial索引用於地理空間數據查詢,適用於GIS應用。
