mysqldump导出数据库排除指定表

我们经常需要备份数据库,导出数据库表结构

我们会使用mysqldump

由于数据库表太多,我们可能在导出的时候想排除指定的表,有没有办法呢

mysql> use mytest
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables; #查看当前数据库中,所有的表的情况
+--------------------+
| Tables_in_mytest |
+--------------------+
| sms_send_blacklist |
| td_b_sendobject |
| test |
| ti_o_sms |
| ti_o_smsbak |
+--------------------+
5 rows in set (0.00 sec)

将ti_o_sms表排除在外

[mysql@testvm01 baks]$ mysqldump --databases mytest --ignore-table=mytest.ti_o_sms > mytest.sql
[mysql@testvm01 baks]$ ll
total 7112
-rw-rw-r--. 1 mysql mysql 7280800 Jan 3 20:27 mytest.sql

[mysql@testvm01 baks]$ grep "ti_o_sms" mytest.sql
-- Table structure for table `ti_o_smsbak`
DROP TABLE IF EXISTS `ti_o_smsbak`;
CREATE TABLE `ti_o_smsbak` (
-- Dumping data for table `ti_o_smsbak`
LOCK TABLES `ti_o_smsbak` WRITE;
/*!40000 ALTER TABLE `ti_o_smsbak` DISABLE KEYS */;
/*!40000 ALTER TABLE `ti_o_smsbak` ENABLE KEYS */;

排除多张表

[mysql@testvm01 baks]$ mysqldump --databases mytest --ignore-table=mytest.ti_o_sms --ignore-table=mytest.ti_o_smsbak > mytest02.sql
[mysql@testvm01 baks]$ ll
total 14220
-rw-rw-r--. 1 mysql mysql 7277128 Jan 3 20:29 mytest02.sql
-rw-rw-r--. 1 mysql mysql 7280800 Jan 3 20:27 mytest.sql

    A+
发布日期:2021年11月05日  所属分类:未分类

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: