Running show grants;
indicates that I am logged in as a user with all privileges on a database.
Running show table status;
results in an error. And the error does not show the username I am logged in as!
It's as if, for this command, mysql forgets who I am. Other select statements work fine. Can anyone explain this? How to fix? Thanks.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.13-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show grants;
+---------------------------------------------------------------------------------------------------------------------+
| Grants for php@localhost |
+-----------------------------------------开发者_StackOverflow社区----------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'php'@'localhost' IDENTIFIED BY PASSWORD '*8F5FF90079BC601F8EA7C148475658E65A0C029D' |
| GRANT ALL PRIVILEGES ON `sunflower_work`.* TO 'php'@'localhost' |
| GRANT ALL PRIVILEGES ON `news_demo`.* TO 'php'@'localhost' |
| GRANT ALL PRIVILEGES ON `news_base`.* TO 'php'@'localhost' |
+---------------------------------------------------------------------------------------------------------------------+
4 rows in set (0.00 sec)
mysql> show table status from sunflower_work;
ERROR 1143 (42000): SELECT command denied to user ''@'%' for column 'uid' in table 'users'
mysql>
update... as suggested by Tomalak, I deleted the user and recreated with fuller privileges and no password. Still the problem persists. Now it looks like this:
mysql> show grants;
+--------------------------------------------------+
| Grants for php@localhost |
+--------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'php'@'localhost' |
+--------------------------------------------------+
1 row in set (0.00 sec)
mysql> show table status;
ERROR 1143 (42000): SELECT command denied to user ''@'%' for column 'uid' in table 'users'
mysql>
The issue is probably that you have VIEWS in your database. The views are probably created with specific rights.
As you can tell by your error message, it complains about a different user than the one you are logged in is. This is because for a view you can specify how to determine what rights the view has to look at data.
When you go to your database, try typing:
SHOW FULL TABLES IN sunflower_work WHERE TABLE_TYPE NOT LIKE '%table%';
Then you may wish to look into the rights of the specific views that are there.
The answers here helped me with my specific problem. Many thanks! A view was the culprit as described above.
I got into trouble because the database in question was created from a backup of a remote database which had different users. The 'broken' view was 'defined' by a user I didn't have locally. Even root was unable to run the crashing query.
Changed the view's 'DEFINER' to a valid local user and the problem was solved!
ALTER
DEFINER = 'a_valid_user'@'localhost'
VIEW my_view
AS
SELECT .....
Check out ALTER VIEW documentation for MySQL 5.5
Many thanks again!
Take schema backup before proceeding.
If you just imported a dump file in mysql, delete that import and related schema and start again.
open the dump file in a text editor and delete all lines with the following content /*! ~~~~ DEFINER='root' @'%' SQL SECURITY DEFINER */
~ Represents a random number generated by workbench during export
This solution is a quick fix and intended for development environments only.
精彩评论