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

首先出现的状况是mysql -uroot -p123456能够登陆,mysql

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

那就直接登陆进去执行下面一条语句便可。 ubuntu

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

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

若是命令行都登不上去的话,app

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

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网站

使用默认用户名密码登陆.net

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>

执行刚才那个更新语句,命令行

退出来code

重启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 apparmor

root@ubuntu:~#apt-get update
root@ubuntu:~#apt-get install mysql-server
相关文章
相关标签/搜索