[Mysql] mysql忘记root密码,修改密码方法


本文总阅读量

1、修改my.cnf文件,在[mysqld]下添加’skip-grant-tables’参数:

cat /usr/local/mysql/etc/my.cnf

1
2
3
4
5
6
7
8
[mysqld]
!include /usr/local/mysql/etc/mysqld.cnf
port = 3306
basedir = /usr/local/mysql/
socket = /usr/local/mysql/tmp/mysql.sock
pid-file = /usr/local/mysql/var/mysql.pid
datadir = /usr/local/mysql/var/
skip-grant-tables

2、重启mysql进程:

1
/etc/init.d/mysql restart

3、进入mysql控制台,修改mysql密码:

1
2
3
4
5
6
7
8
mysql> USE mysql ; 
Database changed
mysql> UPDATE user SET Password = password ( '12345678' ) WHERE User = 'root' ;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> flush privileges ;
Query OK, 0 rows affected (0.00 sec)
mysql> quit

4、注释掉my.cnf配置文件下的skip-grant-tables这行参数,重新启动mysql:

1
/etc/init.d/mysql restart

5、测试密码是否修改成功,能否正常登陆控制台:

1
mysql -u root -p12345678
目录
  1. 1. 1、修改my.cnf文件,在[mysqld]下添加’skip-grant-tables’参数:
  2. 2. 2、重启mysql进程:
  3. 3. 3、进入mysql控制台,修改mysql密码:
  4. 4. 4、注释掉my.cnf配置文件下的skip-grant-tables这行参数,重新启动mysql:
  5. 5. 5、测试密码是否修改成功,能否正常登陆控制台:

Proudly powered by Hexo and Theme by Lap
本站访客数人次
© 2020 zeven0707's blog