您的位置:首页 > 数据库 > MySQL

【小平工作日志】mysql找回密码、更改密码系列问题

2016-11-01 00:00 344 查看
1.先修改mysql配置。在[mysqld]的段中加上一句:skip-grant-tables ,保存并退出。

vim /etc/my.cnf

#例如:
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables

2.重启mysql。

service mysqld restart #重启mysql 版本不同重启的方式不一样

3.登录并修改密码。

[root@iZ2866kru0eZ ~]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.32 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;
Query OK, 0 rows affected (0.00 sec)

Rows matched: 2 Changed: 0 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.01 sec)
mysql> quit
Bye

4.把mysql配置更改回来。去掉skip-grant-tables。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  MySQL