以下将是重置MySQL密码教程
本教程环境:
[root@localhost ~]# cat /etc/redhat-release
CentOS release 6.5 (Final)
[root@localhost ~]# mysql --version
mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1
[root@localhost ~]#
step1.停止在运行的mysql服务
[root@localhost ~]# service mysqld stop
step2.编辑配置文件etc/my.cnf
,添加如下图所示内容:
[root@localhost ~]# vim /etc/my.cnf
保存退出!
step3.重启服务
[root@localhost ~]# service mysqld restart
step4.进如mysql数据库,修改密码
[root@localhost ~]# mysql -uroot
mysql> show databases;
mysql> use mysql
mysql> show tables;
mysql> update user set password=PASSWORD('123456') where user='root'
MySQL> flush privileges; #刷新权限
mysql> quit
注:
update user set password=PASSWORD('newpassword') where user='root'
可以修改密码
但是在mysql 5.7
版本中不存在password字段,所以我们要用下面命令修改:update user set authentication_string=password('123456') where user='root';