Error:access denied for user ' root ' @ ' localhost ' (using Password:no)
Found:
mysql-u [email protected]-P success
Mysql-u Root-p failed
mysql> SELECT user, host from Mysql.user;
ERROR 1142 (42000): SELECT command denied to user "@ ' localhost ' for table ' user '
Mysql> SELECT USER (), Current_User ();
+--------------------------+----------------+
| USER () | Current_User () |
+--------------------------+----------------+
| [email protected] @localhost | @localhost |
+--------------------------+----------------+
1 row in Set (0.01 sec)
Cause: Root sets the password and needs to clear the root password.
The following can solve the problem (scenario I):
1) Service mysqld stop
2) Mysqld_safe--user=mysql--skip-grant-tables--skip-networking &
3) mysql-u Root
4) Setup new MySQL root user password
Use MySQL;
Select User,host,password from Mysql.user;
+------+-----------+-------------------------------------------+
| user | Host | password |
+------+-----------+-------------------------------------------+
| Root | localhost | *cf1e6a25c954b638a451d6|
| Root | Centos64 | |
| Root | 127.0.0.1 | |
| | localhost | |
| | Centos64 | |
+------+-----------+-------------------------------------------+
Update Mysql.user Set Password=password ("***********") where user= ' root ';
Select User,host,password from Mysql.user;
+------+-----------+-------------------------------------------+
| user | Host | password |
+------+-----------+-------------------------------------------+
| Root | localhost | *cf1e6a25c954b638a451d6 |
| Root | Centos64 | *cf1e6a25c954b638a451d6|
| Root | 127.0.0.1 | *cf1e6a25c954b638a451d6|
| | localhost | |
| | Centos64 | |
+------+-----------+-------------------------------------------+
Flush privileges;
Quit
5) Stop MySQL server:service mysqld stop
6) Start MySQL Server and test it:
Service mysqld Start
Mysql-u root-p
SELECT USER (), Current_User ();
+----------------+----------------+
| USER () | Current_User () |
+----------------+----------------+
| [Email protected] | [Email protected] |
+----------------+----------------+
1 row in Set (0.00 sec)
The following can solve the problem (scenario two):
First log in to MySQL with a scheme, and then set the root password to null
Use MySQL;
Update user set Password=password ("****************") where user= ' root ';
Flush privileges;
Quit
=========================
When authorizing the error:
ERROR 1044 (42000): Access denied for user ' root ' @ '% ' to database ' MDM '
First of all, this is the root user operation, so the permissions on this database is absolutely the highest, but if the non-root user operation, it is possible that the issue of permissions, requires the root user authorization.
appear above the error, it is possible, in fact, it should be said basically because the my.cnf file has skip-name-resolve parameters, this parameter causes this can not parse hostname or other ways of login, so login to any user, matching time does not go [email Protected] ' localhost ', or 127.0.0.1 or:: 1, but kept's walk [email protected] '% '.
Then look at the specific permissions of the root user in each of these ways:
Mysql> select * from User\\g;
I have three types of root in the parsing method is: host:bidevedw\_db, Host:: 1, Host:%
The general situation also has host:127.0.0.1, host:localhost my inside to which two kinds of delete.
Please note!
Note the red font portion of each record above grant_priv:y
This means that the root user who resolves the login in this way has grant permission, and Y indicates that there is permission to restrict other users, and n means no.
Here happens, is the reason we are looking for, because my/my.cnf file has skip-name-resolve parameters, so root is resolved to the @ '% ' mode login, so there is no Grant_priv permissions.
Workaround:
1, in the case of not restarting the MySQL service, only need to add the-H parameter when logging in.
For example: (a). /usr/local/mysql/bin/mysql-uroot-p123456-h::1
(b)./usr/local/mysql/bin/mysql-uroot-p123456-h127.0.0.1
(c)./usr/local/mysql/bin/mysql-uroot-p123456-hlocalhost
2, need to restart MySQL. Removing the Skip-name-resolve parameter----has not been verified. But I remember, if it was removed, there would be a lot of warning messages in the log. I added this parameter because of the warning message.
REF:
http://blog.itpub.net/27099995/viewspace-1362951/
ERROR 1142 (42000): SELECT command denied to user "@ ' localhost ' for table ' user '