当前位置:Gxlcms > 数据库问题 > 忘记mysql的root密码,如何重设密码

忘记mysql的root密码,如何重设密码

时间:2021-07-01 10:21:17 帮助过:22人阅读


Linux:

1、编辑MySQL配置文件my.cnf

vi /etc/my.cnf    #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables

[mysqld]

skip-grant-tables

:wq!  #保存退出

service mysqld restart  #重启MySQL服务

PS:也可以不修改配置文件,直接用以下命令启动MySQL,以不检查权限的方式启动;
    safe_MySQLd --skip-grant-tables &  

2、进入MySQL控制台

mysql -uroot -p   #直接按回车,这时不需要输入root密码。

3、修改root密码

update mysql.user set password=password(‘123456‘) where User="root" and Host="localhost";

flush privileges;  #刷新系统授权表

grant all on *.* to ‘root‘@‘localhost‘ identified by ‘123456‘ with grant option;

4、取消/etc/my.cnf中的skip-grant-tables

vi /etc/my.cnf   编辑文件,找到[mysqld],删除skip-grant-tables这一行

:wq!  #保存退出

5、重启mysql

service mysqld restart    #重启mysql,这个时候mysql的root密码已经修改为123456

6、用新密码进入mysql控制台

mysql -uroot -p  #进入mysql控制台

123456 #输入密码


Windows:
  1.以系统管理员身份登陆系统。


  2.打开cmd-----net start 查看mysql是否启动。启动的话就停止net stop mysql.


  3.我的mysql安装在d:\usr\local\mysql4\bin下。


  4.跳过权限检查启动mysql.

  d:\usr\local\mysql\bin\mysqld-nt --skip-grant-tables


  5.重新打开cmd。进到d:\usr\local\mysql4\bin下:
  d:\usr\local\mysql\bin\mysqladmin -u root flush-privileges password "newpassword"
  d:\usr\local\mysql\bin\mysqladmin -u root -p shutdown  这句提示你重新输密码。


  6.在cmd里net start mysql


  7.使用新密码登录

忘记mysql的root密码,如何重设密码

标签:linux   mysql   windows   忘记密码   

人气教程排行