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>