mysqldump 导出数据库报错“does not exist when using LOCK TABLES”
现象如下: [ptmind@tz-manage01 ~]$ mysqldump -uroot -p2008 schedule >schedule.sql mysqldump: Got error: 1449: The user specified as a definer ('ptmind'@'192.168.16.0/255.255.255.0') does not exist when using LOCK TABLES
[ptmind@tz-manage01 ~]$ mysqldump -uroot -p2008 -h192.168.18.52 -x schedule >/tmp/schedule.sql mysqldump: Got error: 1449: The user specified as a definer ('ptmind'@'192.168.16.0/255.255.255.0') does not exist when using LOCK TABLES
排查解决: 1. 在网上查了一下,说root用户访问权限不够,于是为root用户授权;
grant all privileges on *.* to root@"192.168.0.0/255.255.0.0" identified by "2008";
1.1 确认root授权成功; mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; +-------------------------------------------------+ | query | +-------------------------------------------------+ | User: 'root'@'%'; | | User: 'root'@'localhost'; | +-------------------------------------------------+ 9 rows in set (0.00 sec)
1.2 授权完成,再次执行dump语句;
[ptmind@tz-manage01 ~]$ mysqldump -uroot -p2008 -h192.168.18.52 schedule >/tmp/schedule.sql mysqldump: Got error: 1449: The user specified as a definer ('ptmind'@'192.168.16.0/255.255.255.0') does not exist when using LOCK TABLES
1.3 发现执行还是报错,于是测试导出一个mysql其它数据库试一下,发现能够正常导出,说明不是权限问题。
[ptmind@tz-manage01 ~]$ mysqldump -uroot -p2008 -h192.168.18.52 monitor >/tmp/schedule.sql [ptmind@tz-manage01 ~]$ ll /tmp/
-rw-rw-r--. 1 ptmind ptmind 4550638 Jul 29 16:46 schedule.sql
1.4,解决 经以上排查,确认应该是schedule 数据库在使用状态,所以导出数据时报错,在mysqldump时使用 -x 选项解决此问题。 --lock-all-tables,-x 在开始导出之前,提交请求锁定所有数据库中的所有表,以保证数据的一致性。这是一个全局读锁,并且自动关闭 --single-transaction 和 --lock-tables 选项。
[ptmind@tz-manage01 ~]$ mysqldump -uroot -p2008 -h192.168.18.52 -x schedule >/tmp/schedule.sql
-rw-rw-r--. 1 ptmind ptmind 786 Jul 29 16:47 schedule.sql
|