查看一下user表,错误的起因就是在这里, root的plugin被修改成了auth_socket,用密码登陆的plugin应该是mysql_native_password
mysql> select user, plugin from mysql.user;
+-----------+-----------------------+
| user | plugin |
+-----------+-----------------------+
| root | auth_socket |
| mysql.sys | mysql_native_password |
| dev | mysql_native_password |
+-----------+-----------------------+
3 rows in set (0.01 sec)
-- -------------------------------------------
mysql> update mysql.user set authentication_string=PASSWORD('password'), plugin='mysql_native_password' where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
然后重启服务
sudo service mysql restart
ok!