MySQL 備份時過濾掉某些庫 以及 去掉Warning提示信息


 

在對mysql進行完整備份時使用--all-database參數

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

數據導入的時候,可以先登陸mysql數據庫中,使用source /root/all.sql進行導入。

如果想要在mysqldump備份數據庫時過濾掉某些庫,這種情況下就不能使用--all-database了,而是使用--database。如下備份數據庫時過濾掉information_schema、mysql 、test和hehe_db庫

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

+--------------------+
| Database           |
+--------------------+
| information_schema |
| haha_db            |
| hehe_db            |
| mysql              |
| test               |
| tech_db            |
| yaya_db            |
| mimi_db            |
| lala_db            |
+--------------------+
9 rows in set (0.00 sec)

[root@fangfull-backup ~]# mysql -uroot -p -e "show databases"|grep -Ev "Database|information_schema|mysql|test|hehe_db"
Enter password: 
haha_db
tech_db 
yaya_db 
mimi_db 
lala_db 

[root@fangfull-backup ~]# mysql -uroot -p -e "show databases"|grep -Ev "Database|information_schema|mysql|test|hehe_db"|xargs
Enter password: 
haha_db tech_db yaya_db mimi_db lala_db 

[root@fangfull-backup ~]# mysql -uroot -p -e "show databases"|grep -Ev "Database|information_schema|mysql|test|hehe_db"|xargs mysqldump -uroot -p --databases > mysql_dump.sql
Enter password:

                                                                                                                                                               

mysql5.6以上版本在直接使用密碼登錄mysql的時候,會出現提示信息"Warning: Using a password on the command line interface can be insecure."!

[root@kevin ~]# mysql -pkevin@123 -e "show databases"           
Warning: Using a password on the command line interface can be insecure.
+--------------------+
| Database           |
+--------------------+
| information_schema |
| confluence         |
| dtin_uat           |
| dtinlog_uat        |
| mysql              |
| nextcloud_db       |
| performance_schema |
| xbtdb              |
+--------------------+

要想屏蔽掉這個提示信息,方法是:將提示信息重定向到/dev/null,即忽略掉提示信息。

[root@kevin ~]# mysql -pkevin@123 -e "show databases" 2>/dev/null            
+--------------------+
| Database           |
+--------------------+
| information_schema |
| confluence         |
| dtin_uat           |
| dtinlog_uat        |
| mysql              |
| nextcloud_db       |
| performance_schema |
| xbtdb              |
+--------------------+

過濾掉mysql某些庫的操作如下:
[root@kevin ~]# mysql -pkevin@123 -e "show databases" 2>/dev/null |grep -Ev "Database|information_schema|mysql"             
confluence
dtin_uat
dtinlog_uat
nextcloud_db
performance_schema
xbtdb


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM