Solve the MySQL connection problem in Ubuntu (error 1045 (28000): Access denied for user 'root' @ 'localhost &

Source: Internet
Author: User

My system is ubuntu8.04. The newly installed MySQL always has an error prompt when it enters the MySQL tool:

# Mysql-uroot-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 finally found the solution:

Switch to the root user and enter the MySQL bin directory,
Root @ CPS-desktop:/usr/local/MySQL/bin #/etc/init. d/MySQL stop

Root @ CPS-desktop:/usr/local/MySQL/bin #./mysqld_safe -- user = MySQL -- skip-grant-tables -- skip-networking
&

Root @ CPS-desktop:/usr/local/MySQL/bin #./MySQL-u root MySQL

Mysql> Update user SET Password = PASSWORD ('newpassword') Where
User = 'root ';
Mysql> flush privileges;
Mysql> quit;

Finally, restart the database:
Root @ CPS-desktop:/usr/local/MySQL/bin #/etc/init. d/MySQL restart

Root @ CPS-desktop:/usr/local/MySQL/bin # mysql-u root-P

Enter Password: <enter the new password newpassword>

Mysql>

Related Article

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.