Innodb使用
DATA DIRECTORY='directory'
選項容許建立默認數據目錄以外的獨立表空間php
innodb_file_per_table
,必須指定完整路徑名--skip-symbolic-links
選項啓動mysql服務,操做系統必須支持realpath()
調用data directory
or index directory
不能使用包含mysql數據目錄的路徑名DATA DIRECTORY
選項innodb_flush_method
引起的問題root@localhost*5.6.28-log[(none)] >show variables like 'innodb_flush_method'; +---------------------+----------+ | Variable_name | Value | +---------------------+----------+ | innodb_flush_method | O_DIRECT | +---------------------+----------+ 1 row in set (0.00 sec) root@localhost*5.6.28-log[(none)] >use test Database changed root@localhost*5.6.28-log[test] >create table t1 (id int primary key,n varchar(10)) data directory='/data2/mysql56'; ERROR 1030 (HY000): Got error -1 from storage engine root@localhost*5.6.28-log[test] >show errors; +-------+------+----------------------------------+ | Level | Code | Message | +-------+------+----------------------------------+ | Error | 1030 | Got error -1 from storage engine | +-------+------+----------------------------------+ 1 row in set (0.00 sec) root@localhost*5.6.28-log[(none)] >use test Database changed root@localhost*5.6.28-log[test] >show variables like 'innodb_flush_method'; -- 去掉`o_direct` +---------------------+-------+ | Variable_name | Value | +---------------------+-------+ | innodb_flush_method | | +---------------------+-------+ 1 row in set (0.00 sec) root@localhost*5.6.28-log[test] >create table t1 (id int primary key,n varchar(10)) data directory='/data2/mysql56'; Query OK, 0 rows affected (0.00 sec)
5.6.24沒有問題,使用
O_DIRECT
mysql
root@localhost*5.6.24[(none)] >use test Database changed root@localhost*5.6.24[test] >show variables like 'innodb_flush_method'; +---------------------+----------+ | Variable_name | Value | +---------------------+----------+ | innodb_flush_method | O_DIRECT | +---------------------+----------+ 1 row in set (0.00 sec) root@localhost*5.6.24[test] >create table t1 (id int primary key,n varchar(10)) data directory='/data2/mysql56'; Query OK, 0 rows affected (0.10 sec) root@localhost*5.6.24[test] >insert into t1 select 1,'a'; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 root@localhost*5.6.24[test] >insert into t1 select 2,'b'; Query OK, 1 row affected (0.00 sec) Records: 1 Duplicates: 0 Warnings: 0 root@localhost*5.6.24[test] >commit; Query OK, 0 rows affected (0.00 sec) root@localhost*5.6.24[test] >select * from t1; +----+------+ | id | n | +----+------+ | 1 | a | | 2 | b | +----+------+ 2 rows in set (0.00 sec)
xb
備份問題進行備份sql
innobackupex --defaults-file=/etc/my.cnf xb_backup/ .160106 04:58:51 >> log scanned up to (1633545) 160106 04:58:51 Executing UNLOCK TABLES 160106 04:58:51 All tables unlocked 160106 04:58:51 Backup created in directory '/root/xb_backup//2016-01-06_04-58-46' 160106 04:58:51 [00] Writing backup-my.cnf 160106 04:58:51 [00] ...done 160106 04:58:51 [00] Writing xtrabackup_info 160106 04:58:51 [00] ...done xtrabackup: Transaction log of lsn (1633545) to (1633545) was copied. 160106 04:58:51 completed OK!
還原數據庫
innobackupex --apply-log --use-memory=512M xb_backup/2016-01-06_04-58-46/ InnoDB: New log files created, LSN=1633555 InnoDB: Highest supported file format is Barracuda. InnoDB: 128 rollback segment(s) are active. InnoDB: Waiting for purge to start InnoDB: 5.6.24 started; log sequence number 1633804 xtrabackup: starting shutdown with innodb_fast_shutdown = 1 InnoDB: FTS optimize thread exiting. InnoDB: Starting shutdown... InnoDB: Shutdown completed; log sequence number 1633814 160106 05:06:52 completed OK!
[root@localhost ~]# mysqladmin shutdown 160106 05:08:50 mysqld_safe mysqld from pid file /data/mysqld.pid ended [1]+ Done ./bin/mysqld_safe (wd: /usr/local/mysql) (wd now: ~) [root@localhost ~]# rm /data/ auto.cnf error.log ibdata1 ib_logfile0 ib_logfile1 mysql/ performance_schema/ test/ [root@localhost ~]# rm /data/* -rf [root@localhost ~]# rm /data2/mysql56/test/ -rf
[root@localhost ~]# cp -a xb_backup/2016-01-06_04-58-46/* /data/ [root@localhost ~]# chown mysql.mysql -R /data [root@localhost ~]# ll /data total 112660 -rw-r----- 1 mysql mysql 386 Jan 6 04:58 backup-my.cnf -rw-r----- 1 mysql mysql 12582912 Jan 6 05:06 ibdata1 -rw-r--r-- 1 mysql mysql 50331648 Jan 6 05:06 ib_logfile0 -rw-r--r-- 1 mysql mysql 50331648 Jan 6 05:06 ib_logfile1 drwx------ 2 mysql mysql 4096 Jan 6 04:58 mysql drwx------ 2 mysql mysql 4096 Jan 6 04:58 performance_schema drwx------ 2 mysql mysql 45 Jan 6 04:58 test -rw-r----- 1 mysql mysql 113 Jan 6 05:06 xtrabackup_checkpoints -rw-r----- 1 mysql mysql 420 Jan 6 04:58 xtrabackup_info -rw-r----- 1 mysql mysql 2097152 Jan 6 05:06 xtrabackup_logfile [root@localhost ~]# cd /usr/local/mysql [root@localhost mysql]# ./bin/mysqld_safe & [1] 28470 [root@localhost mysql]# 160106 05:10:20 mysqld_safe Logging to '/data/error.log'. 160106 05:10:20 mysqld_safe Starting mysqld daemon with databases from /data [root@localhost mysql]# [root@localhost mysql]# msyql -bash: msyql: command not found [root@localhost mysql]# mysql root@localhost*5.6.24[(none)] >select * from test.t1; +----+------+ | id | n | +----+------+ | 1 | a | | 2 | b | +----+------+ 2 rows in set (0.00 sec) root@localhost*5.6.24[(none)] >\! ls -lh /data/test total 112K -rw-r----- 1 mysql mysql 8.4K Jan 6 04:58 t1.frm -rw-r----- 1 mysql mysql 96K Jan 6 04:58 t1.ibd -rw-r----- 1 mysql mysql 26 Jan 6 04:58 t1.isl root@localhost*5.6.24[(none)] >insert into test.t1 select 3,'c'; Query OK, 1 row affected (0.01 sec) Records: 1 Duplicates: 0 Warnings: 0 root@localhost*5.6.24[(none)] >select * from test.t1; +----+------+ | id | n | +----+------+ | 1 | a | | 2 | b | | 3 | c | +----+------+ 3 rows in set (0.00 sec)
[root@localhost mysql]# mysqladmin shutdown 160106 05:12:12 mysqld_safe mysqld from pid file /data/mysqld.pid ended [1]+ Done ./bin/mysqld_safe [root@localhost mysql]# mv /data/test/t1. t1.frm t1.ibd t1.isl [root@localhost mysql]# mkdir /data2/mysql56/test [root@localhost mysql]# chown mysql.mysql -R /data2/mysql56/ [root@localhost mysql]# mv /data/test/t1.ibd /data2/mysql56/test/ [root@localhost mysql]# ./bin/mysqld_safe & [root@localhost mysql]# mysql root@localhost*5.6.24[(none)] >select * from test.t1; +----+------+ | id | n | +----+------+ | 1 | a | | 2 | b | | 3 | c | +----+------+ 3 rows in set (0.01 sec) root@localhost*5.6.24[(none)] >insert into test.t1 select 4,'d'; Query OK, 1 row affected (0.01 sec) Records: 1 Duplicates: 0 Warnings: 0 root@localhost*5.6.24[(none)] >select * from test.t1; +----+------+ | id | n | +----+------+ | 1 | a | | 2 | b | | 3 | c | | 4 | d | +----+------+ 4 rows in set (0.00 sec) root@localhost*5.6.24[(none)] >\! ls -l /data/test/ total 16 -rw-r----- 1 mysql mysql 8580 Jan 6 04:58 t1.frm -rw-r----- 1 mysql mysql 26 Jan 6 04:58 t1.isl root@localhost*5.6.24[(none)] >\! ls -l /data2/mysql56/test total 96 -rw-r----- 1 mysql mysql 98304 Jan 6 05:13 t1.ibd root@localhost*5.6.24[(none)] >
root@localhost*5.6.24[test] >delimiter // root@localhost*5.6.24[test] >CREATE PROCEDURE `insert_t1` (IN count int) BEGIN declare start int; declare i int; SELECT MAX(id) FROM test.t1 INTO start; set i = start+1; while i < count do insert into test.t1 select i,repeat('a',10); set i = i+1; end while; END // root@localhost*5.6.24[test] >delimiter ; root@localhost*5.6.24[test] >call insert_t1(200); Query OK, 1 row affected (0.53 sec) root@localhost*5.6.24[test] >\! ls -l /data2/mysql56/test total 96 -rw-r----- 1 mysql mysql 98304 Jan 6 05:33 t1.ibd
innodb
表使用data directory
選項時,若是innodb_flush_method=O_DIRECT
,將會遇到1030錯誤