mysql本地root密码重置

自己机子上mysql的root密码忘掉了,不用重装mysql。直接查看/修改root密码。

1. 停掉mysql服务。 

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

linux:  $sudo  mysql.server stop

2. 跳过mysql身份认证

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

linux:$sudo mysqld_safe

3.  进入mysql数据库

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

linux:  $sudo mysql -uroot -p

密码提示按Enter直接进入

4.  查看原来的密码

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

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

5.  修改密码

use mysql

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

flush privileges;

exit

6.  重启mysql服务

windows : net start mysql

linus : $sudo mysql.server start

 

 

 

你可能感兴趣的:(数据库)