PopOS! 21.04
(衍生自 Ubuntu)
终端中输入:
sudo cat /etc/mysql/debian.cnf
显示 mysql 的配置信息
# Automatically generated for Debian scripts. DO NOT TOUCH! [client] host = localhost user = debian-sys-maint password = HKUpeOYOJDSGcOY1 socket = /var/run/mysqld/mysqld.sock [mysql_upgrade] host = localhost user = debian-sys-maint password = HKUpeOYOJDSGcOY1 socket = /var/run/mysqld/mysqld.sock
上方的信息中包含用户和密码
终端输入:
mysql -u debian-sys-maint -p
再输入密码后,进入 mysql
进入mysql修改密码
use mysql; update user set authentication_string='' where user='root'; ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456'; FLUSH privileges;
重启 Mysql(必须重启!)
sudo systemctl restart mysql.service
(如果上面这个重启命令不行,用下面这个命令试试)
sudo service mysql start sudo service mysql stop sudo service mysql restart
使用新密码登录:
mysql -u root -p
输入密码进入 mysql
参考链接:
- ubuntu19 安装mysql8.0.17 后重新设置root密码
- Linux下Mysql-8.0修改密码
有时候mysql经常会出现一些稀奇古怪的问题,很多情况为了节省时间都是选择重装,附上重装过程。
# 完全卸载 sudo rm /var/lib/mysql/ -R sudo rm /etc/mysql/ -R sudo apt-get autoremove mysql* --purge sudo apt-get remove apparmor # 安装 sudo apt-get update sudo apt-get install mysql-server
节选自:Mysql:ERROR 1698 (28000): Access denied for user ‘root’@‘localhost’