linux ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 安装mysql

linux ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 安装mysql

一般这个错误是由密码错误引起,解决的办法自然就是重置密码。

我使用的是root账户。

1.重置密码的第一步就是跳过MySQL的密码认证过程,方法如下:

#vi /etc/my.cnf

在[mysqld]后面第一行添加“skip-grant-tables”用来跳过密码验证的过程

linux ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 安装mysql

保存文档并退出:

#:wq
2.接下来我们需要重启MySQL:

/etc/init.d/mysql restart(有些用户可能需要使用/etc/init.d/mysqld restart)

 

3.重启之后输入#mysql即可进入mysql。

4.接下来就是用sql来修改root的密码

mysql> use mysql;
mysql> update user set password=password("你的新密码") where user="root";
mysql> flush privileges;
mysql> quit

linux ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 安装mysql

到这里root账户就已经重置成新的密码了。

5.编辑my.cnf,去掉刚才添加的内容

linux ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 安装mysql

6.,然后重启MySQL。大功告成!

linux ERROR 1045 (28000): Access denied for user ‘root‘@‘localhost‘ (using password: YES) 安装mysql