mysql完整备份时过滤掉某些库

时间:2022-04-23
本文章向大家介绍mysql完整备份时过滤掉某些库,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

mysql进行完整备份时使用--all-database参数 比如: #mysqldump -u root -h localhost -p --all-database > /root/all.sql

数据导入的时候,可以先登陆mysql数据库中,使用source /root/all.sql进行导入。

问题: 想要在mysqldump备份数据库的时候,过滤掉某些库。 这种情况mysqldump备份的时候就不能使用--all-database了,而是使用--database。

如下:备份数据库的时候过滤掉information_schema、mysql 、test和jkhw_db库

[root@fangfull-backup ~]# mysql -uroot -p -e "show databases" Enter password:

+--------------------+ | Database | +--------------------+ | information_schema | | hqsb_db               | | jkhw_db             | | mysql                 | | test                    | | tech_db             | | hqtime_o2o_db | | hq_o2o_db        | | hqtime_o2o_db_new | +--------------------+ 9 rows in set (0.00 sec)

操作方法: [root@fangfull-backup ~]# mysql -uroot -p -e "show databases"|grep -Ev "Database|information_schema|mysql|test|jkhw_db" Enter password: hqsb_db tech_db hqtime_o2o_db hq_o2o_db hqtime_o2o_db_new [root@fangfull-backup ~]# mysql -uroot -p -e "show databases"|grep -Ev "Database|information_schema|mysql|test|jkhw_db"|xargs Enter password: hqsb_db tech_db hqtime_o2o_db hq_o2o_db hqtime_o2o_db_new [root@fangfull-backup ~]# mysql -uroot -p -e "show databases"|grep -Ev "Database|information_schema|mysql|test|jkhw_db"|xargs mysqldump -uroot -p --databases > mysql_dump.sql Enter password: