mysqldump: Got error: 1044

.版本

1)操作系统

 cat /etc/issue
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Kernel \r on an \m

 cat /proc/version
Linux version 2.6.32-504.el6.x86_64 ([email protected]) (gcc version 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) ) #1 SMP Wed Oct 15 04:27:16 UTC 2014

2)mysql数据库版本

mysql --version
mysql  Ver 14.14 Distrib 5.6.27, for Linux (x86_64) using  EditLine wrapper


2.问题描述

  使用mysqldump 导出某张表时报如下错误:

mysqldump --default-character-set=utf8 -h127.0.0.1 -P3306 -utest -proot  shao test1 > test1.sql;
Warning: Using a password on the command line interface can be insecure.
mysqldump: Got error: 1044: Access denied for user 'test'@'127.0.0.1' to database 'shao' when doing LOCK TABLES
 ##从上面的报错中我们可以看出来是因为test用户没有lock tables权限,所以导出失败()

  查看test用户权限

mysql> show grants for [email protected];
+-------------------------------------------------------------------------------------------------------------+
| Grants for [email protected]                                                                                   |
+-------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test'@'127.0.0.1' IDENTIFIED BY PASSWORD '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B' |
| GRANT SELECT ON `shao`.`test1` TO 'test'@'127.0.0.1'                                                        |
+-------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)
##'test'@'127.0.0.1'用户 只有USAGE和SLEECT权限

3.解决方案

  该问题可以通过如下方案解决:

1)给用户授予 lock tables权限

mysql> grant lock tables on shao.* to 'test'@'127.0.0.1';
Query OK, 0 rows affected (0.00 sec)

mysql> grant lock tables on shao.test1 to 'test'@'127.0.0.1';
ERROR 1144 (42000): Illegal GRANT/REVOKE command; please consult the manual to see which privileges can be used
mysql> 
##在给某个表授予lock tables时会报ERROR 1144 (42000)错,授予锁定某个库下所有表的lock tables权限

2) 在mysqldump中加入--single-transaction参数

mysqldump --default-character-set=utf8 -h127.0.0.1 -P3306 -utest -proot --single-transaction shao test1 > test1.sql;

3) 在mysqldump中加入--single-transaction参数

mysqldump --default-character-set=utf8 -h127.0.0.1 -P3306 -utest -proot --skip-lock-tables shao test1 > test1.sql



##

  在使用mysqldump时,默认--lock-tables(-l)是打开的,当dump中使用--skip-lock-tables来关闭,使用--single-transaction也会自动关闭---lock-tables




你可能感兴趣的:(error,Lock,Access,for,when,MysqlDump,denied,US,got,doing,Tabl)