$ sudo mysql -u root -p
$ ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new-password';
$ sudo service mysql stop
$ sudo service mysql start
参考链接:
https://blog.csdn.net/Exception_sir/article/details/82111014
https://blog.csdn.net/jlu16/article/details/82809937
注意第2篇的评论区。