mysql Filtering Some Libraries During Full Backup

  • 2021-07-26 08:59:31
  • OfStack

The--all-database parameter is used for mysql full backup

For example:

#mysqldump -u root -h localhost -p --all-database > /root/all.sql

When importing data, you can log in to mysql database first and import it using source/root/all. sql.

Question:

Want to filter out some libraries when mysqldump backs up the database.

In this case, instead of using--all-database for mysqldump backup, use--database.

As follows: Filter out the information_schema, mysql, test, and jkhw_db libraries when backing up the database

[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)

Operation method:

[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:


Related articles: