解決辦法:
1. vim mysqld.cnf 路徑:/etc/mysql/mysql.conf.d
在[mysqld]下新增skip-grant-tables
2. 重啟mysql服務
service mysql restart
3.連線mysql並設定密碼
mysql -u root
mysql>
flush privileges
mysql> GRANT ALL PRIVILEGES ON *.* TO root@localhost IDENTIFIED BY "123456";
參考部落格:https://blog.csdn.net/lisongjia123/article/details/57418989