1.修改mysqld.cnf配置文件
sudo gedit /etc/mysql/mysql.conf.d/mysqld.cnf
在[mysqld]中加入
skip-grant-tables
2.重啓mysql
service mysql restart
3.修改密碼
mysql -u root
use mysql;
update user set authentication_string=password('新密碼'),plugin='mysql_native_password' where user='root';
flush privileges;
exit
4.註釋掉mysqld.cnf配置文件添加的skip-grant-tables
5.重啓mysql