fav*_*adi 7 mysql mysqldump backup view
当使用mysqldump
备份MySQL中,我得到了下面的错误。
mysqldump --all-databases --routines >> all.sql
mysqldump: Couldn't execute 'show table status like 'hdkien'': SELECT command denied to user 'tungbt'@'192.168.12.197' for column 'id' in table 'hdcn_hd' (1143)
Run Code Online (Sandbox Code Playgroud)
hdkien
是一种观点
CREATE ALGORITHM=UNDEFINED DEFINER=`tungbt`@`192.168.12.197` SQL SECURITY DEFINER VIEW `hdcn`.`hdkien` AS (...striped...)
Run Code Online (Sandbox Code Playgroud)
用户tungbt
@192.168.12.197
已经有权在表上进行选择hdcn_hd
,我可以hdkien
毫无问题地从视图中进行选择。
mysql> select * from hdkien limit 1;
+------+-----------+
| id | shd |
+------+-----------+
| 876 | ADFADFA1 |
+------+-----------+
Run Code Online (Sandbox Code Playgroud)
更多信息:
mysql-community-server-5.5.37-4.el6.x86_64
为什么我在运行时出现错误,我该mysqldump
如何解决?
更新 1 (2014/04/17)
我mysqldump
与用户一起运行'root'@'localhost'
。
mysql> show grants for 'root'@'localhost';
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root@localhost |
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '...striped...' WITH GRANT OPTION |
| GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION |
+----------------------------------------------------------------------------------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
用户'tungbt'@'192.168.12.197'
是视图的定义者hdcn.hdkien
(并且SQL SECURITY
是DEFINER
.
+------------------------------------------------------------------------------------------------------------------+
| Grants for tungbt@192.168.12.197 |
+------------------------------------------------------------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'tungbt'@'192.168.12.197' IDENTIFIED BY PASSWORD '...striped...' |
| GRANT ALL PRIVILEGES ON `hdcn`.* TO 'tungbt'@'192.168.12.197' |
+------------------------------------------------------------------------------------------------------------------+
Run Code Online (Sandbox Code Playgroud)
更新 2
$ mysql -ANe"SELECT USER(),CURRENT_USER()"
+----------------+----------------+
| root@localhost | root@localhost |
+----------------+----------------+
Run Code Online (Sandbox Code Playgroud)
更新 3
mysql> SELECT COUNT(1) MySQLGrantsCount,VERSION() MySQLVersion FROM information_schema.columns WHERE table_schema='mysql' AND table_name='user';
+------------------+--------------+
| MySQLGrantsCount | MySQLVersion |
+------------------+--------------+
| 42 | 5.5.37-log |
+------------------+--------------+
Run Code Online (Sandbox Code Playgroud)
您需要具有SHOW VIEW 权限。我在 2013 年 12 月写过这篇文章:获取 MySQL 数据库架构备份所需的最低权限是什么?
在那篇文章中,我展示了 mysqldump 的这些最低权限
你应该运行这个命令:
SHOW GRANTS FOR tungbt@192.168.12.197;
Run Code Online (Sandbox Code Playgroud)
如果SHOW VIEW
不存在,这就是原因。
当你这样做时
mysqldump --all-databases --routines >> all.sql
Run Code Online (Sandbox Code Playgroud)
我看你没有指定用户和密码。在这种情况下,您没有以root@localhost
. 您必须明确指定 root 用户
mysqldump -uroot -p --all-databases --routines >> all.sql
Run Code Online (Sandbox Code Playgroud)
您将看到密码提示。输入 root@localhost 密码,您就可以正常运行了。
您也可以指定密码
mysqldump -uroot -ppassword --all-databases --routines >> all.sql
Run Code Online (Sandbox Code Playgroud)
如果您正在使用.~/my.cnf
但仍然收到错误,您可能会在错误 #70907 mysqldump 中遇到这种情况:无法执行 'show table status': SELECT command denied to user '
如果配置文件确实.~/my.cnf
是/root/.my.cnf
,则可能您没有以 Linux 根用户身份登录。您可能必须运行 sudo。
请运行此命令
mysql -ANe"SELECT USER(),CURRENT_USER()"
Run Code Online (Sandbox Code Playgroud)
如果您没有看到root@localhost
两次,那么您没有正确进行身份验证。
在.my.cnf
您需要确保用户和密码在该[client]
部分下
[client]
user=root
password=rootpassword
Run Code Online (Sandbox Code Playgroud)
不在[mysql]
节之下。
我忍不住看了那个错误报告并想知道以下内容:既然你有 DEFINER= tungbt
@ 192.168.12.197
,那么 root@localhost 的行为有可能像tungbt
@192.168.12.197
吗?我这样说是因为根据CREATE VIEW 上的MySQL 文档:At view definition time, the view creator must have the privileges needed to use the top-level objects accessed by the view. For example, if the view definition refers to table columns, the creator must have some privilege for each column in the select list of the definition, and the SELECT privilege for each column used elsewhere in the definition.
您可以将视图的定义器更改为 root@localhost 并再次尝试 mysqldump
小智 5
我遇到了类似的问题,无法以 root 身份在我的视图上执行 mysqldump:
mysqldump: Couldn't execute 'show create table `v_view01`': View 'my_db.v_view01' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them (1356)
Run Code Online (Sandbox Code Playgroud)
就我而言,这是因为我的底层架构发生了变化,因此依赖它的视图不再有效。即使我以 root 身份执行转储,它仍然显示“或视图调用者缺乏权限......”。解决方案很简单:
drop view v_view01
Run Code Online (Sandbox Code Playgroud)
由于视图已经过时,我只是将其删除,然后 mysqldump 像平常一样进行。