mysql完整備份時過濾掉某些庫

散盡浮華發表於2016-10-11

 


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:

 

相關文章