数据库备份写入过程中
源代码:
[root@localhost ~]# mysqldump -uroot -pMyNewPass4! -F -B it --default-character-set=utf8 --single-transaction -e | gzip > /root/mysql_back_`date +%F`.sql.gz
警告信息1:
Warning: Using a password on the command line interface can be insecure.
意思是说:在命令行界面上使用密码可能是不安全的,不能直接把密码写在脚本中。
解决办法:
既然密码不能直接外露,那么我们就写在/etc/my.cnf下面:
[root@localhost ~]# vim /etc/my.cnf
添加自己的信息,注意socket的位置
[client]
port=3306
socket=/var/lib/mysql/mysql.sock
default-character-set = utf8mb4
host = localhost
user = root
password = 'MyNewPass4!'
可以通过find / -name mysql.sock 查找具体位置,修改用户密码部分
mysqldump --defaults-extra-file=/etc/my.cnf -F -B it --default-character-set=utf8 --single-transaction -e | gzip > /root/mysql_back_`date +%F`.sql.gz
警告信息2:
Warning: A partial dump from a server that has GTIDs will by default include the GTIDs of all transactions, even those that changed suppressed parts of the database. If you don't want to restore GTIDs, pass --set-gtid-purged=OFF. To make a complete dump, pass --all-databases --triggers --routines --events.
在上面的脚本中加入 --set-gtid-purged=off 或者–gtid-mode=OFF这两个参数设置就可以了。