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
相關文章
相關標籤/搜索