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.

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

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

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

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

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

文章討論了使用準備好的語句,輸入驗證和強密碼策略確保針對SQL注入和蠻力攻擊的MySQL。(159個字符)


熱AI工具

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

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

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

AI Hentai Generator
免費產生 AI 無盡。

熱門文章

熱工具

WebStorm Mac版
好用的JavaScript開發工具

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

Dreamweaver CS6
視覺化網頁開發工具

PhpStorm Mac 版本
最新(2018.2.1 )專業的PHP整合開發工具

MinGW - Minimalist GNU for Windows
這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。