1.關掉mysql服務,打開系統設置最後的mysql,然後將mysql先關掉
2.生成一個文件命名mysql-init,文件中放入:一句話,這句話不同版本不一樣,如下:(括號裡面不包含)
alter user ‘root’@‘localhost’ identified by ‘新密碼’;(MySQL 5.7.6 and later)
set password for ‘root’@‘localhost’=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(‘你在文件中定義的新密碼’),password_expired = ’N’ where user = ‘root’ and host = ‘localhost’;
flush privileges;
quit;
./mysql -u root -p
輸入你的新密碼就好了
參考: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小節