Modification Method of Forgetting Password in Installing mysql under mac

  • 2021-08-21 21:42:02
  • OfStack

1. Installing MySQL database under mac

1. Download the MySQL database

Download address: Visit http://www.mysql.com/downloads/ in official website of MySQL for download.

Enter the download interface of MySQL (http://www.mysql.com/downloads/mysql/)

Download the dmg files of x86 and 64bit: directly select the bottom "No thanks, just take me to downloads!"

2. Install the MySQL database

After opening the MySQL installation package, click to install the main program pkg file.

3. Start the MySQL database

Open MYSQL database file mode, open it in system preferences, and click MySQL, start ES50server to start MySQL.

4. The terminal logs in to MySQL database:


mysql -u root -p

Enter, the default password is empty. Enter after password appears.

2. After installing the database, I found that I forgot the database password

1. Shut down the MySQL database first

Turn off MySQL, stop mysql server in System Preferences

Step 2 Enter Safe Mode


? bin sudo su
Password:
Sorry, try again.
Password:
sh-3.2# ./mysqld_safe --skip-grant-tables &
[1] 3477
sh-3.2# 2017-06-27T08:32:37.6NZ mysqld_safe Logging to '/usr/local/mysql-5.7.18-macos10.12-x86_64/data/localhost.err'.
2017-06-27T08:32:37.6NZ mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql-5.7.18-macos10.12-x86_64/data
sh-3.2#

3. Restart 1 terminal


~ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 16
Server version: 5.7.18 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Step 4 Enter commands


mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.06 sec)

Step 5 Reset your password


mysql> SET PASSWORD FOR root@'localhost' = PASSWORD('root');
Query OK, 0 rows affected, 1 warning (0.02 sec)

6. Enter the command again


mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

Related articles: