Linux系统 MySQL出现ERROR1698(28000):Access denied for user root@localhost错误解决方法

service mysql status //查看mysql状态

service mysql start //启动MySQL

mysql -uroot -p   

当输入第三行命令按下回车发现出现ERROR1698(28000):Access denied for user root@localhost时,应该采取办法:

1.在终端继续输入

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

按i进入编辑模式,在[mysqld]这一块中加入skip-grant-tables这句话,按ESC退出编辑,按“:”+wq保存退出。

2.在终端重新输入

mysql -uroot -p

回车进入mysql界面,在该界面输入命令

use mysql;   
update user set authentication_string=password("此处填你设置的密码") where user="root";

flush privileges;

quit  //退出mysql

 

3.重新进入到mysqld.cnf文件中去把刚开始加的skip-grant-tables这条语句给注释掉。命令为:

sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf

进入该文件按i进入编辑模式

#skip-grant-tables

按ESC退出编辑,按“:”+wq保存退出

4.重启MySQL,重新进入mysql

service mysql stop

service mysql start

mysql -uroot -p

如果输入上面三行命令仍出现ERROR1698(28000):Access denied for user root@localhost,此时需重新进入mysqld.cnf,将#skip-grant-tables前面的#删除,保存退出。

5.重新输入mysql -uroot -p,回车进入mysql,在该界面输入:

use mysql;
select user,plugin from user;

此时如果表格中root对应的plugin root的字段是auth_socket,那我们需要将它为下面的mysql_native_password就行了。命令为:

update user set authentication_string=password("此处为你设置的密码"),plugin='mysql_native_password' where user='root';


quit  //退出mysql

6.重新进入到mysqld.cnf文件中去把刚开始加的skip-grant-tables这条语句给注释掉。

7.再次关闭mysql重新启动即可。

service mysql stop 
service mysql start 
mysql -uroot -p

按回车输入你设置的密码即可进入mysql.

 

参考文章:

(1)mysql出现ERROR1698(28000):Access denied for user root@localhost错误解决方法:https://www.itdaan.com/blog/2018/09/04/402f99d0ecd2c3aa8ed2d652d58d202c.html

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值