mysql 1698_MySQL-1698 : Access denied for user 'root'@'localhost'解决方法

用root用户连接MySQL 数据库报"ERROR 1698 : Access denied for user ‘root’@‘localhost’" 错误。

**客户端:**terminal,Navicat,连接都该错误报错误.

**系统环境:**ubuntu 18,MySQL5.7

**原因:**The reason is that recent Ubuntu installation (maybe others also), mysql is using by default the UNIX auth_socket plugin.

Basically means that: db_users using it, will be “auth” by the system user credentias. You can see if your root user is set up like this by doing the following: $ sudo mysql -u root # I had to use “sudo” since is new installation

mysql> USE mysql;

mysql> SELECT User, Host, plugin FROM mysql.user;

±-----------------±----------------------+

| User | plugin |

±-----------------±----------------------+

| root | auth_socket |

| mysql.sys | mysql_native_password |

| debian-sys-maint | mysql_native_password

±-----------------±----------------------+

As you can see in the query, the root user is using the auth_socket plugin

There are 2 ways to solve this:

You can set the root user to use the mysql_native_password plugin

You can create a new db_user with you system_user (recommended)

Option 1: $ sudo mysql -u root # I had to use “sudo” since is new installation

mysql> USE mysql;

mysql> UPDATE user SET plugin=‘mysql_native_password’ WHERE User=‘root’;

mysql> FLUSH PRIVILEGES;

mysql> exit;

$ service mysql restart

Option 2: (replace YOUR_SYSTEM_USER with the username you have) $ sudo mysql -u root # I had to use “sudo” since is new installation

mysql> USE mysql;

mysql> CREATE USER ‘YOUR_SYSTEM_USER’@‘localhost’ IDENTIFIED BY ‘’;

mysql> GRANT ALL PRIVILEGES ON . TO ‘YOUR_SYSTEM_USER’@‘localhost’;

mysql> UPDATE user SET plugin=‘auth_socket’ WHERE User=‘YOUR_SYSTEM_USER’;

mysql> FLUSH PRIVILEGES;

mysql> exit;

$ service mysql restart

Remember that if you use option #2 you’ll have to connect to mysql as your system username (mysql -u YOUR_SYSTEM_USER)

Note: On some systems (e.g., Debian stretch) ‘auth_socket’ plugin is called ‘unix_socket’, so the corresponding SQL command should be: UPDATE user SET plugin=‘unix_socket’ WHERE User=‘YOUR_SYSTEM_USER’;

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值