Error 1045 (28000): Access denied for user root @ localhost (using password: No)

Source: Internet
Author: User

Error Description: After a user is added to MySQL, the error 1045 (28000): Access denied for user may occur during logon. delete user. if the value of user is null, or update null to test 1) delete from user where user is null 2) update user set user = 'test' where user is null. unexpected situation: if the above method does not work and empty users still appear, you can use the graphical user client to delete it.
After the centos is reinstalled, it is found that MySQL is always unavailable.
# The mysqladmin create dbname command always returns mysqladmin: connect to server at 'localhost' failed
# Mysql-u Root @ localhost
> Create Database dbname;
Also, error 1045 (28000): Access denied for user is returned. 'Root' @ 'localhost' (Using password: No)
# Mysql-u root-P
Enter password:
Error 1045 (28000): Access denied for user 'Root' @ 'localhost' (Using password: No)
Use the methods described on the Internet to change the password of the root user:
# Mysqladmin-uroot-P password 'newpassword'
Enter password:
Mysqladmin: connect to server at 'localhost' failed
Error: 'Access denied for user 'Root' @ 'localhost' (Using password: Yes )'
Now I have found the solution as follows (Please test method 3 first, thank you !) :
Method 1:
#/Etc/init. d/MySQL stop
# Mysqld_safe -- user = MySQL -- skip-grant-tables -- skip-Networking &
# Mysql-u root MySQL
Mysql> Update user SET Password = PASSWORD ('newpassword') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
#/Etc/init. d/MySQL restart
# Mysql-uroot-P
Enter Password: <enter the new password newpassword>
Mysql>
Method 2:
Directly use the username and password provided in the [client] section of the/etc/MySQL/Debian. CNF file:
# Mysql-udebian-sys-Maint-P
Enter Password: <enter the password in the [client] section>
Mysql> Update user SET Password = PASSWORD ('newpassword') where user = 'root ';
Mysql> flush privileges;
Mysql> quit
# Mysql-uroot-P
Enter Password: <enter the new password newpassword>
Mysql>
Method 3:
I have not tested this method, because the default password of my root user has been modified by me. If you have time to test it, let me know the result. Thank you!
# Mysql-uroot-P
Enter Password: <enter the password provided in [client] in the/etc/MySQL/Debian. CNF File>
At this point, many problems have been solved!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.