Solution for forgetting the Mysql root User Password on Mac, mysqlroot

Source: Internet
Author: User

Solution for forgetting the Mysql root User Password on Mac, mysqlroot

I haven't gotten the mysql on my computer for a long time, and I forgot my password. But it doesn't matter. We can reset our password.

The principle is to enable the mysql service securely and then update the password-saving table.

First, we need to disable the original mysql service, System Preferences-> MySQL-> Stop MySQL Server

Then open a Terminal and enable mysql in safe mode. No Password is required during connection.

sudo mysqld_safe --skip-grant-tables

Then, run the Terminal command to update the password.

mysql -u rootUPDATE mysql.user SET authentication_string=PASSWORD('your_new_password') WHERE User='root';FLUSH PRIVILEGES;

In the preceding format, you only need to modify your_new_password.

If Mysql is a version earlier than V5.7.9, use the following SQL statement.

UPDATE mysql.user SET Password=PASSWORD('your_new_password') WHERE User='root';

Restart Mysql. Try it.

mysql -uroot -pyour_new_password

Success !!!!

The solution provided by netizens is as follows:

Step 1:

Close the mysql service: Apple-> system preference settings-> at the bottom of the page, click mysql to close the mysql service on the pop-up page (Click stop mysql server)

Step 2:

Enter terminal input:cd /usr/local/mysql/bin/
Enter and log on to the Administratorsudo su
Press enter and enter the following command to disable mysql verification../mysqld_safe --skip-grant-tables &
After you press enter, mysql will automatically restart (mysql in preference settings will change to running)

Step 3:

Enter the command./mysql
Press enter and enter the commandFLUSH PRIVILEGES; 
Press enter and enter the commandSet password for 'root' @ 'localhost' = PASSWORD ('your new password ');

After completing the preceding steps, the password is successfully modified. Now you can use the new password to log on to mysql.

Related Article

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.