MySQL数据库无法连接问题及密码重置

温馨提示:本文最后更新于2023-01-12 18:35:12,某些文章具有时效性,若有错误或已失效,请在下方留言或联系

错误代码:

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

This error is caused by the auth_socket plugin. The simplest solution is to just disable the plugin. Here are the commands to do it:

1. Login to MySQL as root (sudo will bypass password prompt)

$ sudo mysql -u root

2. Change to the mysql database and set the plugin to mysql_native_password for the root user.

mysql> USE mysql;
mysql> UPDATE user SET plugin='mysql_native_password' WHERE User='root';
mysql> FLUSH PRIVILEGES;

3. You have to change the root password for this to work. Even just specifying the current password is fine too, but this command must be executed:

mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password_here';
mysql> exit;

4. Lastly, restart MySQL for the changes to take effect.

$ sudo systemctl restart mysql

5. You can now login to MySQL root as normal, and will no longer encounter the error.

$ mysql -u root -p
声明:本站部分文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。部分文章由注册用户发布,版权归原作者所有,本社区不拥有其著作权,亦不承担相应的法律责任,如你发现本社区有涉嫌抄袭的内容,侵犯了原著者的合法权益,可联系我们进行处理。

给TA赞助
共{{data.count}}人
人已赞助
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索