service mysql stop
sudo find / -name my.cnf
sudo vim /etc/mysql/my.cnf
添加如下内容:
[mysqld] skip-grant-tables
service mysql restart
mysql
use mysql;
update user set authentication_string='password' where user='root';
quit;
sudo vim /etc/mysql/my.cnf
将之前添加的内容注释掉
service mysql restart
mysql -u root -p
参考资料: https://blog.csdn.net/luckytanggu/article/details/80251833