Environment
MySQL version: 5.7.12
Operating system: OSX 10.11
installation files:. dmg files
MYSQL:MYSQL-5.7.12-OSX10.11-X86_64.DMG (note 5.7 is a bit different from the previous field, which is said below)
Step 1
Turn off the MySQL service. Whether you have the MySQL service turned on or not, run the following command for insurance purposes.
sudo /usr/local/mysql/support-files/mysql.server stop
(Note: I have an error here: error! MySQL server PID file could not being found! I go directly to the system Preferences--other (at the bottom) into the mysql--> Close is enough, the second step is the same)
Step 2
Safe mode to start MySQL.
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
(The second step seems to be still not works, as follows:
1. In the terminal, enter the command to add the MySQL path:
Path= "$PATH":/usr/local/mysql/bin Note: As long as the discovery of this error Mysql:command not found use PATH this line of code, and then enter your previous error command line can be
2. Get Administrator Privileges
sudo su (enter your notebook's password)
3. Cross the permission table and log in to MySQL directly
Mysqld_safe--skip-grant-tables--skip-networking &
)
In Safe mode, you can open the MySQL command line window directly without requiring a password.
Step 3
Create a new terminal, change the root password,
Note here that 5.7 compared to previous versions, the password field in the Mysql.user table was changed to: authentication_string
Enter the following command one by one, modify the root password and exit. If you continue to use password, you will get an error and cannot find this field
mysql -u rootUPDATE mysql.user SET authentication_string=PASSWORD(‘my-new-password‘) WHERE User=‘root‘;FLUSH PRIVILEGES;\q
will be my-new-password
replaced with your new password. After running the above command, the root password is changed to the password you set.
Test
Run the following command to test if the password was modified successfully.
-u root -p
Then enter the password for your new settings.
If the input is correct, the MySQL command line window should appear, as follows:
Tips
- After installing MySQL through the. dmg file, the MySQL icon appears in the system settings and provides a GUI service to open and close the MySQL service.
- command line to open and close the MySQL service
sudo /usr/local/mysql/support-files/mysql.server startsudo /usr/local/mysql/support-files/mysql.server stop
Reference
Reset MySQL root Password in OSX
How Mac starts MySQL:
Http://jingyan.baidu.com/article/48a42057e2b2b9a9242504a2.html
MySQL cannot log on to the root user solution
http://www.euryugasaki.com/archives/853
MySQL change root user password for Mac