当前位置: 代码迷 >> 综合 >> ubuntu19.04+mysql5.7 中 Mysql:ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘
  详细解决方案

ubuntu19.04+mysql5.7 中 Mysql:ERROR 1698 (28000): Access denied for user ‘root‘@‘localhost‘

热度:62   发布时间:2023-12-12 01:32:35.0

首先出现的情况是mysql -uroot -p123456可以登录,

但是网站配置了账号却显示Mysql:ERROR 1698 (28000): Access denied for user 'root'@'localhost'。

那就直接登录进去执行下面一条语句即可。 

mysql.user表里authentication_string这个字段是密码,以后会逐渐废弃password字段

UPDATE mysql.user SET authentication_string=PASSWORD('root的密码'), PLUGIN='mysql_native_password' WHERE USER='root';

如果命令行都登不上去的话,

使用cat命令查看默认用户名密码。

sudo cat /etc/mysql/debian.cnf 

root@ubuntu:~# sudo cat /etc/mysql/debian.cnf 
# Automatically generated for Debian scripts. DO NOT TOUCH!
[client]
host     = localhost
user     = debian-sys-maint
password = 0XRu7iGdhb6UT8Af
socket   = /var/run/mysqld/mysqld.sock
[mysql_upgrade]
host     = localhost
user     = debian-sys-maint
password = 0XRu7iGdhb6UT8Af
socket   = /var/run/mysqld/mysqld.sock

使用默认用户名密码登录

root@ubuntu:~# mysql -udebian-sys-maint -p0XRu7iGdhb6UT8Af
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 63
Server version: 5.7.25-1 (Ubuntu)Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> 

执行刚才那个更新语句,

退出来

重启mysql。

生效。

嗯。

实在解决不了,就卸载重装吧。

root@ubuntu:~#rm /var/lib/mysql/ -R
root@ubuntu:~#rm /etc/mysql/ -R
root@ubuntu:~#apt-get autoremove mysql* --purge
root@ubuntu:~#apt-get remove apparmorroot@ubuntu:~#apt-get update
root@ubuntu:~#apt-get install mysql-server
  相关解决方案