Home  >  Article  >  Database  >  Detailed explanation of the sample code for solving the problem of forgotten mysql password in MAC

Detailed explanation of the sample code for solving the problem of forgotten mysql password in MAC

黄舟
黄舟Original
2017-03-17 13:53:381360browse

This article mainly introduces the relevant information on the solution to the forgotten mysql password in MAC. Friends in need can refer to the

Solution to the forgotten mysql password in MAC

My recent project used MySQL. I had installed one before, but I forgot the password I set at that time, and then I embarked on the bumpy road of changing the password. After searching a lot of information on Baidu and Google, I still found that there are pitfalls for programmers everywhere. So I decided to write a blog covering solutions to forgotten passwords in various situations.

Situation 1: Download the dmg file directly from the mysql official website for installation, forget the password

1.Close the mysql server

sudo /usr/local/mysql/support-files/mysql.server stop

2.Enter the directory

cd /usr/local/mysql/bin

3. Obtain permission

sudo su

4.Restart the server

./mysqld_safe --skip-grant-tables &

5.control + D to exit editing

6.Configure short command

alias mysql=/usr/local/mysql/bin/mysql

7.Enter mysql

Command mode

mysql
8. Enter the

mysql database

use mysql
9. Obtain change permissions

flush privileges;

10.Reset Password

set password for 'root'@'localhost'=password('新密码');

Case 2: If you often use home-brew installation to install software, you only need to change the path in the above steps. The default installation directory of mysql is /usr/local/Cellar/mysql/ 5.7.16, just change steps 1, 2, and 6 above /usr/local/mysql to /usr/local/Cellar/mysql/5.7.16

Case 3: In this case This is a rather tricky situation. After downloading mysql, I forgot about it for a long time, and then downloaded another one. I found that the database I downloaded first directly prompted me to enter the password. Then enter the command according to situation 1 or 2 and it cannot be modified successfully. Afterwards, modifying my.cnf (now changed to my-default.cnf) according to the method introduced online did not work. If you unfortunately encounter this situation, please follow the steps below

1. Uninstall mysql

 sudo rm /usr/local/mysql

 sudo rm -rf /usr/local/var/mysql

 sudo rm -rf /usr/local/mysql*

 sudo rm -rf /Library/StartupItems/MySQLCOM

 sudo rm -rf /Library/PreferencePanes/My*

 vim /etc/hostconfig and removed the line MYSQLCOM=-YES-rm -rf ~/Library/PreferencePanes/My*

 sudo rm -rf /Library/Receipts/mysql*

 sudo rm -rf /Library/Receipts/MySQL*

 sudo rm -rf /var/db/receipts/com.mysql.*

2. Reinstall mysql

3. In this case, if you still You will be prompted to enter your password, just follow the situation 1 or 2 again

The above is the detailed content of Detailed explanation of the sample code for solving the problem of forgotten mysql password in 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