步骤一:打开终端
$sudo /etc/init.d/mysql stop
$sudo mkdir -p /var/run/mysqld
$sudo chown mysql:mysql /var/run/mysqld
$sudo /usr/bin/mysqld_safe --skip-grant-tables --skip-networking &
步骤二:打开新终端
$mysql -u root #免密码登录
mysql>use mysql;
mysql>update user set authentication_string=PASSWORD("你的密码放到这") where User='root';
mysql>update user set plugin="mysql_native_password";
mysql>flush privileges;
mysql>quit;
$sudo /etc/init.d/mysql stop
$sudo /etc/init.d/mysql start # reset mysql
步骤三:再打开新终端
$mysql -u root -p
应该可以成功了,有什么问题重启一下系统应该也就好了
---------------------
详情
原文:https://blog.csdn.net/weixin_42353109/article/details/81431051
---------------------