1.首先關閉mysql服務
sudo /usr/local/mysql/support-files/mysql.server stop
2.用安全模式啓動mysql
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3.使用root帳號登陸mysql服務
/usr/local/mysql/bin/mysql -u root
4.修改root帳號的密碼(其實這運行的是sql語句)
update mysql.user set authentication_string=password('qingyun1') where user='root' and Host = 'localhost';
刷新權限表:flush privileges;
5.關閉安全模式,正常的重啓mysql
sudo /usr/local/mysql/support-files/mysql.server restart
6.正常的使用root帳號和密碼鏈接mysql
/usr/local/mysql/bin/mysql -u root -p
mysql
忘記密碼,強行修改:sql
中止Mysql服務
sudo /usr/local/mysql/support-files/mysql.server stop
進入終端輸入:
cd /usr/local/mysql/bin/
sudo su
禁止mysql驗證功能
./mysqld_safe --skip-grant-tables &
安全
./mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的新密碼';
rest
- 中止 mysql server. 一般是在 '系統偏好設置' > MySQL > 'Stop MySQL Server'或者:
sudo /usr/local/mysql/support-files/mysql.server stop
2.打開終端輸入:
sudo /usr/local/mysql/bin/mysqld_safe --skip-grant-tables
3.打開另外一個新終端輸入:
sudo /usr/local/mysql/bin/mysql -u root
UPDATE mysql.user SET authentication_string=PASSWORD('新密碼') WHERE User='root';
FLUSH PRIVILEGES;
\q
4.重啓
sudo /usr/local/mysql/support-files/mysql.server restart
*以上方法針對 mysqlV5.7.9, 舊版的mysql請使用:
UPDATE mysql.user SET Password=PASSWORD('新密碼') WHERE User='root';