How can I forget the mysql password on MAC?
How can I forget the mysql password in MAC?
Recently, MySQL was used in the project. I installed one before, but forgot the password set at that time, and then embarked on the rough road of changing the password. After Google posted a pile of data on Baidu, it found that it was a trap for programmers everywhere. As a result, I made up my mind to write a blog covering solutions for forgetting my password in various situations.
Scenario 1: Download the dmg file on the mysql official website and install it. Forget the password.
1. Disable the mysql server
sudo /usr/local/mysql/support-files/mysql.server stop
2. Enter the Directory
cd /usr/local/mysql/bin
3. Get Permissions
sudo su
4. Restart the server
./mysqld_safe --skip-grant-tables &
5. control + D Exit editing
6. Configure short commands
alias mysql=/usr/local/mysql/bin/mysql
7. Enter mysql command mode
mysql
8. Enter the mysql database
use mysql
9. Get the change permission
flush privileges;
10. Reset the password
Set password for 'root' @ 'localhost' = password ('new password ');
Scenario 2: If you often use home-brew installation to install software, you only need to change the path in the preceding steps, by default, mysql is installed in/usr/local/Cellar/mysql/5.7.16, you only need to change steps 1, 2, and 6 above/usr/local/mysql to/usr/local/Cellar/mysql/5.7.16.
Case 3: This is a very difficult situation. After downloading mysql, I forgot about it for a long time and then downloaded another one, if the Database downloaded first is found, the system prompts you to enter the password. Then, enter the command as required. After according to the method introduced on the Internet to modify my. cnf (now changed to my-default.cnf) is useless. If this happens unfortunately, follow these steps:
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 are still prompted to enter the password, perform the operation again based on the Case 1 or case 2.
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!