忘记MySQL的root密码
Table of Contents
- 忘记MySQL的root密码
- 编辑MySQL配置文件my.cnf
- 进入MySQL控制台
- 修改root密码
- 取消/etc/my.cnf中的skip-grant-tables
- 重启mysql
- 进入mysql控制台
忘记MySQL的root密码
编辑MySQL配置文件my.cnf
编辑文件,找到[mysqld],在下面添加一行skip-grant-tables
vi /etc/my.cnf
[mysqld]
skip-grant-tables
:wq!
保存退出
重启MySQL服务
service mysqld restart
进入MySQL控制台
mysql -uroot -p
修改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;
取消/etc/my.cnf中的skip-grant-tables
编辑文件,找到[mysqld],删除skip-grant-tables这一行
vi /etc/my.cnf
重启mysql
service mysqld restart
进入mysql控制台
mysql -uroot -p #进入mysql控制台
All articles on this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated.