mysql新建表96k_innodb表 手工导入导出
上一篇文章介紹了“innobackupex 熱備指定庫表操作”,分析其整個過程,就是將表的字典和數(shù)據(jù)文件導(dǎo)出在導(dǎo)入的原理,那么針對單表的備份與恢復(fù)(新實例或者新庫中恢復(fù)),我們可以直接采用物理導(dǎo)出innodb表的辦法。
具體操作如下:
1.將備份表加鎖,導(dǎo)出cfg。
mysql> select * from t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 2 |
| 3 |
| 4 |
+------+
7 rows in set (0.00 sec)
mysql> flush table t1 with read lock;
Query OK, 0 rows affected (0.01 sec)
發(fā)現(xiàn)t1生成了cfg文件。
[root@222 test]# ls
db.opt t1.cfg t1.frm t1.ibd t2.frm t2.ibd
執(zhí)行unlock tables ,cfg文件回收。
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
[root@222 test]# ls ../test/
db.opt t1.frm t1.ibd t2.frm t2.ibd
2.在unlock tables前,將t1的cfg和ibd文件備份。
[root@222 test]# cp t1.ibd t1.cfg /home/backup/
3.創(chuàng)建一個新庫,并創(chuàng)建相同結(jié)構(gòu)的t1表。
mysql> create database test1;
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> use test1;
Database changed
mysql>
mysql> create table t1 like test.t1;
Query OK, 0 rows affected (0.03 sec)
4.刪除新建的t1表空間。
mysql> alter table t1 discard tablespace;
Query OK, 0 rows affected (0.02 sec)
發(fā)現(xiàn)新建的t1表空間的ibd文件被清除。
[root@222 test]# ls ../test1/
db.opt t1.frm
5.將備份的t1表的cfg和ibd文件拷貝到新建的庫下。
[root@222 test]# cd /home/backup/
[root@222 test1]# ll -trh
總用量 116K
-rw-rw----. 1 mysql mysql 61 12月 16 09:49 db.opt
-rw-rw----. 1 mysql mysql 8.4K 12月 16 09:49 t1.frm
-rw-r-----. 1 root root 96K 12月 16 09:51 t1.ibd
-rw-r-----. 1 root root 354 12月 16 09:51 t1.cfg
[root@222 test1]# chown -R mysql.mysql *
[root@222 test1]#
[root@222 test1]#
[root@222 test1]# ll -trh
總用量 116K
-rw-rw----. 1 mysql mysql 61 12月 16 09:49 db.opt
-rw-rw----. 1 mysql mysql 8.4K 12月 16 09:49 t1.frm
-rw-r-----. 1 mysql mysql 96K 12月 16 09:51 t1.ibd
-rw-r-----. 1 mysql mysql 354 12月 16 09:51 t1.cfg
6.執(zhí)行新建t1表導(dǎo)入表空間操作。
mysql> alter table t1 import tablespace;
Query OK, 0 rows affected (0.08 sec)
7.查詢結(jié)果和第1步備份的表一致,操作完成
mysql> select * from test1.t1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
| 2 |
| 3 |
| 4 |
+------+
7 rows in set (0.00 sec)
btw.
a.由于新表存在cfg文件,在刪除庫操作的時候會報錯,
ERROR 1010 (HY000): Error dropping database (can't rmdir './test1/', errno: 17)
如果使用innobackupex備份,并導(dǎo)入的exp文件,則會發(fā)現(xiàn)刪除庫后,exp文件無法刪除,那么手工將exp文件刪除,在刪除庫即可。
如果使用如上方法手工命令方式導(dǎo)入cfg文件,在刪除庫時報錯,但是查看庫文件時發(fā)現(xiàn)無文件,則在執(zhí)行一遍即可;對于新導(dǎo)入的cfg文件,可以在次執(zhí)行如下命令,則cfg文件消失。
mysql> flush table t1 for export;
Query OK, 0 rows affected (0.00 sec)
[root@222 test1]# ll -trh
總用量 116K
-rw-rw----. 1 mysql mysql 61 12月 16 09:49 db.opt
-rw-rw----. 1 mysql mysql 8.4K 12月 16 09:56 t1.frm
-rw-r-----. 1 mysql mysql 96K 12月 16 09:56 t1.ibd
-rw-r-----. 1 mysql mysql 355 12月 16 09:57 t1.cfg
mysql>
mysql>
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
[root@222 test1]# ll -trh
總用量 112K
-rw-rw----. 1 mysql mysql 61 12月 16 09:49 db.opt
-rw-rw----. 1 mysql mysql 8.4K 12月 16 09:56 t1.frm
-rw-r-----. 1 mysql mysql 96K 12月 16 09:56 t1.ibd
b.發(fā)現(xiàn)手工命令行方式備份恢復(fù)更加便捷,但是會有一個鎖表的過程,那么則根據(jù)不同情況選擇不同方式進行備份,對于線上有寫入的表采用innobackupex方式,不會導(dǎo)致復(fù)制延遲;對于無寫入的表,直接采用加鎖導(dǎo)入cfg文件方式,操作更加便捷。
OK,done。
總結(jié)
以上是生活随笔為你收集整理的mysql新建表96k_innodb表 手工导入导出的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 复仇者联盟4百度云资源怎么下载
- 下一篇: 为什么我的python没有run_为什么