首页 > 代码库 > centos修改mysql密码或者进入mysql后解决Access denied for user ''@'localhost' to database 'mysql错误

centos修改mysql密码或者进入mysql后解决Access denied for user ''@'localhost' to database 'mysql错误

原因是MySQL的密码有问题


用mysql匿名用户可以进入数据库,但是看不见mysql数据库.


解决办法:
具体操作步骤:
关闭mysql:
# service mysqld stop
然后:
# mysqld_safe --skip-grant-tables
开启另一个终端并启动mysql:
# service mysqld start
mysql -u root
mysql> use mysql
mysql> UPDATE user SET Password=PASSWORD(‘root‘) WHERE user=‘root‘;
mysql> flush privileges;
mysql>\q


到这里密码已经修改成功,
mysql -u root -p

centos修改mysql密码或者进入mysql后解决Access denied for user ''@'localhost' to database 'mysql错误