mysql--重置密码

阅读更多
http://blog.51cto.com/legehappy/1979492

解决Mysql忘记密码:

1、首先停止正在运行的MySQL进程:
[root@cml5 ~]# systemctl stop mysqld

2、以安全模式启动MySQL:

[root@cml5 ~]# /usr/local/mysql/bin/mysqld_safe--skip-grant-tables &
##或者在my.cnf文件下添加,执行完后就删除掉
skip-grant-tables

[root@cml5 ~]# cat /etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/mydata
socket=/usr/local/mysql/mysql.sock
log_bin=/usr/local/mysql/mydata/mysql-bin
server-id=1
skip-grant-tables


然后重启mysql
进入mysql(免密码)
然后修改密码;
3、完成以后就可以免密进入MySQL了,然后修改密码:

(3)运行 /usr/local/mysql/bin/mysql -u root -p 按Enter键进入
[root@cml5 ~]#  /usr/local/mysql/bin/mysql -u root -p

mysql> use mysql; 
mysql> update user set password=password('123') where user='root' and host='localhost'; 
##假如是mysql5.7之后的就password字段改成了authentication_string:
mysql> update user set authentication_string=password('redhat') where user='root'and host='localhost';
mysql> flush privileges; 
mysql> ALTER user 'root'@'localhost' identified by 'redhat';
Query OK, 0 rows affected (0.00 sec)
mysql> 
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

你可能感兴趣的:(mysql)