问题
Awhile back I deleted and messed around with some functions in XAMPP.
I reinstalled it and moved/renamed my folder with all my other files so I now have a new xampp directory that's empty and fresh.
But when I try to use any database functionality it gives me error(s) like the one below:
SELECT command denied to user ''@'localhost' for table 'users'
What's wrong?
Thanks.
回答1:
The user has not been given privileges to read the tables.
When creating an user for the database through the cpanel of your host, you can give the user the privileges.
Or read this documentation to do it through MySql command,
http://dev.mysql.com/doc/refman/5.1/en/grant.html
回答2:
you can solve through Enabling the use of SELECT
GRANT SELECT ON db.table TO 'user'@'localhost';
or
Grant all on db.table to 'user'@'localhost';
回答3:
I've just gave the access to the added user, to use phpMyAdmin
database, and it works perfectly:
GRANT SELECT,UPDATE,DELETE,INSERT ON phpmyadmin.* TO user@'localhost' IDENTIFIED BY 'PASSWORD';
回答4:
For me, the user before the at sign being empty was key to figuring out the problem.
I had an account ''@localhost
(it showed up at <anonymous>@localhost
in mysqladmin) that mysql was logging me into instead of the user I requested. This is because mysql selects your user based on some logic and not the requested user name alone.
Deleting the anonymous user fixed the problem.
来源:https://stackoverflow.com/questions/17376637/xampp-select-command-denied-to-user-localhost-for-table-users