Home >Database >Mysql Tutorial >What to do if you forget your MYSQL database password under MAC

What to do if you forget your MYSQL database password under MAC

小云云
小云云Original
2017-12-08 09:29:112512browse

Mysql is a relational database. It is often used in daily work. But what should you do when the database is unavailable for a long time or the database password is forgotten under other circumstances? This article mainly introduces the quick solution for forgetting the MYSQL database password under the Mac operating system and teaches you to reset the MYSQ password. It has certain reference value. Interested friends can refer to it. I hope it can help you.

Quick solution for forgotten MYSQL database password under Mac operating system

1. In the system preferences, stop the MYSQL service.;

2. cd/usr/local/ mysql-...../bin

sudo ./mysqld_safe--skip-grant-tables

3. Log in to MySQL;

mysql

4. Leave the password of root user blank;

mysql> update mysql.user set password=‘' whereUser='root'; 
mysql> flush privileges; 
mysql> quit

5. Restart the MySQL service,

6. Add password mysql> mysqladmin -u root -p password 123 Change the password to 123

Another method from netizens:

#step1:

Turn off the mysql service: Apple->System Preferences->Click mysql at the bottom and close the mysql service in the pop-up page (click stop mysql server)

step2:

Enter the terminal and enter: cd /usr/local/mysql/bin/
After pressing Enter, log in with administrator rights sudo su
After pressing Enter, enter the following command to disable the mysql verification function. /mysqld_safe --skip-grant-tables &
After pressing Enter, mysql will automatically restart (the status of mysql in the preferences will change to running)

step3:

Enter the command ./mysql
After pressing Enter, enter the command FLUSH PRIVILEGES;
After pressing Enter, enter the command SET PASSWORD FOR 'root'@ 'localhost' = PASSWORD('your new password');

After completing the above steps, the password has been successfully changed. Now you can use the newly set password to log in to mysql. Everyone, hurry up and give it a try.

Related recommendations:

How to change the MySQL database password?

How to use the command line to change the MySQL database password

How to retrieve the mysql database password if you forget it, personal test available

The above is the detailed content of What to do if you forget your MYSQL database password under MAC. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn