1、更新mysqld.conf文件:
sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
在【mysqld】下增加
skip-grant-tables
2、然后重启mysql服务:
sudo /etc/init.d/mysql restart
3、无密码登录mysql:
mysql
use mysql;
update user set host='%' where user='root';
更新密码:
alter user 'root'@'%' identified with mysql_native_password by 'admin'
4、将skip_grant_tables注释掉并重启mysql
5、重新登录:
mysql -u root -p
tip: 又又又改了
mysql_8.4.0_community更新密码:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.4.0
mysql> alter user 'root'@'localhost' identified by '123456';
好像又改回去了
如果使用identified with mysql_native_password时,会提示插件mysql_native_password未加载
mysql> alter user root@localhost identified with mysql_native_password by '123456
';
ERROR 1524 (HY000): Plugin 'mysql_native_password' is not loaded