MySQL5.5.38 and MySQL5.7 versions forgot root password, workaround

Source: Internet
Author: User

1, installed in the centos6.5 mysql5.5.38 version, forget how to solve the password?

(1), first close the MYSQLD service

Service Mysqld Stop

(2), start with Mysqld_safe Safe Mode MySQL , use two parameters:

--skip-grant-tables: Skip Authorization Form

--skip-networking: Skip the network, prevent other users to read and write to the database, after the password recovery can open normally

Execute command:

Mysqld_safe--skip-grant-tables--skip-networking &

(3), no password login:

Mysql-u Root

(4), change the password:

mysql> use MySQL; # # #使用 mysql database

mysql> Update user set Password=password (' new password ') where user= ' Root '

mysql> flush Privileges;

Mysql> quit//Exit database

(5), restart the MySQL service

Service mysqld Restart

(6). Log in to MySQL with a new password

Mysql-uroot-p New Password

2, installed in the Centos7 mysql5.7.13 version of Forget Root password, how to solve?

(1), modify the main configuration file my.cnf

Vim/etc/my.cnf

# # #在 [Mysqld] added in

Skip-grant-tables

Save, exit

(2), restart MySQL service

Systemctl MySQL Restart

(3), use the root user login (password is empty, direct enter enter)

Mysql-u root-p

(4), execute the command in MySQL:

mysql> use MySQL;

mysql> Update user set Authentication_string=password (' new password ') where user=< /c5>'root';

Note: In the mysql5.7 version, there is no Password field, using authentication_string Field

mysql> flush Privileges;

Mysql> quit//Exit database

(5), add the original my.cnf configuration file Skip-grant-tables parameters, delete, restart service

sed-i ' s/skip-grant-tables//g/etc/my.cnf '

Systemctl Restart Mysqld

(6), log in to the database test with the new password:

Mysql-u root-p New Password


This article is from the "Keep Keep your" blog, be sure to keep this source http://keep88.blog.51cto.com/11829099/1909970

MySQL5.5.38 and MySQL5.7 versions forgot root password, workaround

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.