Brief introduction
When using MySQL, if you forget the other user's password, you can use the root user to reset, but if you forget the root password, you need to take the following actions to deal with
Experimental environment
- System Environment: centos7.4
- Server IP Address: 192.168.100.71
- Yum Mount directory:/mnt/sr0
- Related source information: mysql-5.5.24, mysql-5.7.17
Note A friend who does not install MySQL can view my previous blog post (with source package included)
Mysql-5.7 Installation Tutorials
Mysql-5.5 Installation Tutorials
Decryption Step one, Mysql-5.5 version forgot password reset 1, turn off Mysql service
[[Email protected]_5 ~]# Service mysqld Stop
2. Start the database with Mysqd_safe combined with--skip-grant-tables
[Email protected]_5 ~]# Mysqld_safe--skip-grant-tables&
[[Email protected]_5 ~]# NETSTAT-ANPT | grep ': 3306 '
3. Modify the Administrator password
[Email protected]_5 ~]# MySQL #进入mysql
mysql> Update Mysql.user Set Password=password (' 456 ') where user= ' root '; #修改root用户密码为 "456"
mysql> flush Privileges; #刷新
Mysql> quit; #退出
4. Start the service again
[Email protected]_5 ~]#!netstat
[[Email protected]_5 ~]# kill-9 22560
[[Email protected]_5 ~]# NETSTAT-ANPT | grep ': 3306 '
[[Email protected]_5 ~]# service mysqld start #启动进程
5. Verify Login
[[Email protected]_5 ~]# mysql-u root-p456 #使用 "456" Password Login
6. Close the service
[[Email protected]_5 ~]# Service mysqld Stop
Second, Mysql-5.7 version forgot password reset 1, turn off the Mysql service
[[Email protected]_1 ~]# systemctl Stop Mysqld.service
2. Modify the master configuration file
[Email protected]_1 ~]# vim/etc/my.cnf
3. Start the service
[Email protected]_1 ~]# systemctl start Mysqld.service
[[Email protected]_1 ~]# NETSTAT-ANPT | grep ': 3306 ' #查看服务进程
4. Modify the Administrator password
[Email protected]_1 ~]# MySQL #进入mysql
mysql> Update Mysql.user set Authentication_string=password (' Hello ') where user= ' root '; #将管理员密码设置为 "Hello"
Mysql> quit;
5. Modify the master configuration file again
[Email protected]_1 ~]# vim/etc/my.cnf
[Email protected]_1 ~]# systemctl restart Mysqld.service #重启服务
6. Verify Login
[[Email protected]_1 ~]# mysql-uroot-phello #指定 "Hello" for password
Detailed Mysql5.5 and version 5.7 forgot admin password handling mechanism