ubuntu mysql 无法进入的解决方法
在 mysql 登陆上遇到了无数次问题,每次解决完就忘了,好恶心,记录一下。
我的版本
查看自己的系统版本和 mysql 版本
lsb_release -a
mysql --version
我的系统是 ubuntu 18.04,MySQL 版本是 5.7.29,版本如果不同请适当参考.
忘记密码
参考 https://www.cnblogs.com/ioan/p/10614623.html
- sudo cat /etc/mysql/debian.cnf
- 使用这个账号登陆
mysql -u debian-sys-maint -p
,输入密码
- 修改 root 账号的密码
update mysql.user set authentication_string=password('123456') where user='root' and Host='localhost';
update mysql.user set plugin='mysql_native_password';
flush privileges;
- 退出当前账户,然后使用 root 登陆。
mysql -u root -p
。成功