ubuntu19.04+mysql5.7 中 Mysql:ERROR 1698 (28000): Access denied for user 'root'@'localhost'
阿新 • • 發佈:2019-04-25
首先出現的情況是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 apparmor
root@ubuntu:~#apt-get update
root@ubuntu:~#apt-get install my