mysql本地root密码重置

  1. 停掉mysql服务。

windows: 管理员身份启动CMD, 执行 net stop mysql

linux: $sudo mysql.server stop

  1. 跳过mysql身份认证

windows: mysqld -nt --skip-grant-tables

linux:$sudo mysqld_safe

  1. 进入mysql数据库

windows: 用管理员另开一个CMD , mysql -uroot -p

linux: $sudo mysql -uroot -p

密码提示按Enter直接进入

  1. 查看原来的密码

select host,user,password from mysql.user;//即可查看到用户和密码

高版本的mysql 没有password字段,修改为: authentication_string

  1. 修改密码

use mysql

update user set authentication_string=password("new_pass") where user="root";

flush privileges;

exit

  1. 重启mysql服务

windows : net start mysql

linus : $sudo mysql.server start

原文地址:https://www.cnblogs.com/cwshuo/p/14500950.html