问题描述:

Ubuntu20.04安装完mysql8之后无法登录,不知道密码

1
mysql -u root 

原因:

系统默认自动配置好了用户和强密码

解决办法:

1
sudo cat /etc/mysql/debian.cnf

查看该文件

image-20250228001017290

利用上面的user 和 passwd 即可登录mysql

1
mysql -u(user) -p(passwd) 

随后修改密码

进入mysql后执行以下命令:

1
2
3
4
5
use mysql; 

update user set authentication_string='' where user='root';

alter user 'root'@'localhost' identified with mysql_native_password by 'xxx'; #修改密码为xxx

退出后即可正常登录

1
mysql -u root -p 

© 2024 oymaster 使用 Stellar 创建

总访问量