mysqldump: Got error: 1045: Access denied for user 'USER'@'localhost' && Couldn't execute 'SHOW FIEL

今天在公司进行版本升级,进行mysql备份时(5.6),遇到了如下问题:

mysqldump

mysqldump  -uUSER -p  DATABASE > /dump/sqldata/xxxdata_`date +%F`_bak.sql
Enter password: 
mysqldump: Got error: 1045: Access denied for user 'USER'@'localhost' (using password: YES) when using LOCK TABLES

mysqldump有一些默认为True的选项

mysqldump --help | grep -i true
and boolean options {FALSE|TRUE}  Value (after reading options)
add-drop-table                    TRUE
add-locks                         TRUE
comments                          TRUE
create-options                    TRUE
disable-keys                      TRUE
extended-insert                   TRUE
lock-tables                       TRUE
quick                             TRUE
quote-names                       TRUE
set-charset                       TRUE
dump-date                         TRUE
secure-auth                       TRUE
triggers                          TRUE
tz-utc                            TRUE

有些选项可能导致我们执行备份的用户权限不足。

解决

1、mysqldump  -uUSER -p  --skip-lock-tables DATABASE > /dump/sqldata/xxxdata_`date +%F`_bak.sql 
2、用root或者再创建一个高权限用户

正当我以为万事大吉的时候

然而又报了如下错误

mysqldump: Couldn't execute 'SHOW FIELDS FROM `XXXXX`': View 'DATABASE.TABLES' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (1356)

大致意思是:不能够执行XXX,视图引用了无效的表或列或定义器/调用者 导致视图无法正常使用。

解决

查看下视图是如何创建的
SHOW CREATE VIEW [视图],可以看到如下部分信息。

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`%`......发现```DEFINDER=“root”``又是权限导致

还是用root来吧。

发布了65 篇原创文章 · 获赞 48 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/DoloresOOO/article/details/103067314
今日推荐