ubuntu 系统解决mysql连接问题(ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO))

切换到root用户,然后进入mysql 的bin目录后,

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;

最后重启数据库:

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: <输入新设的密码newpassword>

这里要注意,mysql的bin目录会不一样,我的是在/usr/bin#

你可能感兴趣的:(ubuntu 系统解决mysql连接问题(ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)))