如何使用 mysqldump 创建只读 MySQL 用户以进行备份?

sti*_*mby 14 mysql backup read-only database-backup

我正在使用该automysqlbackup脚本转储我的 mysql 数据库,但我希望有一个只读用户来执行此操作,这样我就不会将我的根数据库密码存储在纯文本文件中。

我创建了一个这样的用户:

grant select, lock tables on *.* to 'username'@'localhost' identified by 'password';
Run Code Online (Sandbox Code Playgroud)

当我运行mysqldump(通过automysqlbackup或直接)时,我收到以下警告:

mysqldump: Got error: 1044: Access denied for user 'username'@'localhost' to database 'information_schema' when using LOCK TABLES
Run Code Online (Sandbox Code Playgroud)

我做错了吗?我的只读用户需要额外的授权吗?还是只能rootinformation_schema表?这是怎么回事?

编辑:

GAH,现在它可以工作了。我以前可能没有运行 FLUSH PRIVILEGES。

顺便说一句,这种情况多久自动发生一次?

编辑:

不,它不起作用。mysqldump -u username -p --all-databases > dump.sql手动运行不会产生错误,但不会转储 information_schema。automysqlbackup确实会引发错误。

sti*_*mby 1

哎呀...来自手册页mysqldump

mysqldump does not dump the INFORMATION_SCHEMA database. If you name that database explicitly on the command line, mysqldump silently ignores it
Run Code Online (Sandbox Code Playgroud)

似乎手册页已过时(并且确实发出警告),或者automysqlbackup正在对information_schema.

不确定它是什么,但它与用户授权无关。

编辑

是的,这是 2.5.1 版本中的一个错误(在 Ubuntu 10.04 下使用 MySQL 5.1.41)——它会在不应该备份的时候automysqlbackup尝试备份。information_schema

修复:添加information_schemaDBEXCLUDE脚本的第 76 行。