1. Turn off the MySQL service, turn on the system setup last MySQL, then turn off MySQL first
2. Generate a file named Mysql-init, put in the file: a sentence, this sentence different version, the following: (not included in parentheses)
Alter user ' root ' @ ' localhost ' identified by ' new password '; (MySQL 5.7.6 and later)
Set password for ' root ' @ ' localhost ' =password (' new password ');(MySQL 5.7.5 and earlier)
3.cd/usr/local/mysql/bin/
sudo su
Mysql_safe-init-file=/home/me/mysql-init &
Mysql_safe-skip-grant-tables &
./mysql
Flush privileges;
Update mysql.user Set authentication_string = password (' The new password you defined in the file '), password_expired = ' N ' where user = ' root ' and host = ' localhost ';
Flush privileges;
Quit
./mysql-u Root-p
Just type in your new password.
Reference: http://dev.mysql.com/doc/refman/5.7/en/resetting-permissions.html
b.5.3.2.2 resetting the Root Password:unix and Unix-like Systems Section
Initializing the MySQL root password in a MAC environment