mysql5.7 forgot root Password modification method

Source: Internet
Author: User
Tags mysql manual

1. Stop the MySQL service
/etc/init.d/mysqld stop


Restart Service

/usr/local/mysql/bin/mysqld_safe--skip-grant-tables--skip-networking&

Note: The--skip-networking parameter can prevent remote client connections and increase security


Or
Vi/etc/my.cnf
Add the following two lines in [Mysqld]

[Mysqld]
Skip-grant-tables
Skip-networking

Restart service after saving
/etc/init.d/mysqld start

You must remember to change the password after this change.


2. Change the password

/usr/local/mysql/bin/mysql-uroot

mysql> FLUSH privileges;


MySQL 5.7.6 and later versions perform this:

Mysql> ALTER USER ' root ' @ ' localhost ' identified by ' mynewpass ';


MySQL 5.7.5 and Previous versions do this:

mysql> SET PASSWORD for ' root ' @ ' localhost ' = PASSWORD (' Mynewpass ');


Then quit MySQL

Mysql> quit


Note: If ALTER USER fails to execute, try the following command:

UPDATE mysql.user SET authentication_string = PASSWORD (' Mynewpass ')
WHERE User = ' root ' and Host = ' localhost ';
FLUSH privileges;


3. Restart the service

/etc/init.d/mysqld restart

/usr/local/mysql/bin/mysql-uroot-p

You can already log in with the new password you just changed.

The above operations are referenced from the official MySQL manual:
Https://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html


mysql5.7 forgot root Password modification method

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.