创建用户
GRANT USAGE ON *.* TO 'dump'@'localhost' IDENTIFIED BY 'plaintext-pass';
GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON `my-db`.* TO 'dump'@'localhost';
检查权限
mysql> SHOW GRANTS FOR dump@'localhost';
+-----------------------------------------------------------------------------------------------+
| Grants for dump@localhost |
+-----------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'dump'@'localhost' |
| GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON `my-db`.* TO 'dump'@'localhost' |
+-----------------------------------------------------------------------------------------------+
使用侑喜欢的编辑器来创建文件~/.my.cnf
与chmod 400
[client]
user=dump
password=plaintext-pass
仅作为示例创建转储文件夹
mkdir ~/db-dumps
检查是否有效
mysqldump -u dump --hex-blob --routines --triggers my-db | gzip > ~/db-dumps/manual-my-db-dump-`date +%F`.sql.gz
(可选)您可以进行转储daily
,weekly
然后删除所有daily
较旧的月份
#m h dom mon dow command
0 3 * * 0,2-6 /usr/bin/mysqldump -u dump --hex-blob --routines --triggers my-db | gzip > ~/db-dumps/daily-my-db-dump-`date +%F`.sql.gz;
0 3 * * 1 /usr/bin/mysqldump -u dump --hex-blob --routines --triggers my-db | gzip > ~/db-dumps/weekly-my-db-dump-`date +%F`.sql.gz;
0 4 * * * /usr/bin/find ~/db-dumps/ -name "daily-*" -type f -mtime +30 -exec rm -f {} \;
mysqldump
:mysqldump不会转储INFORMATION_SCHEMA数据库。如果您在命令行上显式命名该数据库,则mysqldump会静默忽略它,似乎手册页已过期(确实会发出警告),或者automysqlbackup
正在对dump进行一些其他检查information_schema
。不确定是哪个,但与用户授权无关。