1、编辑MySQL配置文件my.cnf
vi /etc/my.cnf #编辑文件,找到[mysqld],在下面添加一行skip-grant-tables
[mysqld]
skip-grant-tables
:wq! #保存退出
service mysqld restart #重启MySQL服务
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 #输入密码
至此,linux下忘记mysql root密码教程结束。
授权语句
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
本文介绍了一种在Linux环境下重置MySQL root用户密码的方法。通过编辑MySQL配置文件禁用权限验证,然后登录MySQL控制台更新root用户的密码,并重新启用权限验证。
262

被折叠的 条评论
为什么被折叠?



