Detailed Mysql5.5 and version 5.7 forgot admin password handling mechanism

Source: Internet
Author: User
Tags administrator password

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.