mac mysql-8.0.11忘記初始密碼
我在安裝的過程中忽略了初始密碼,導致安裝成功之后無法登陸,搜索網(wǎng)上解決方案,很多都是針對老mysql版本,更新密碼到關鍵步驟會提示語法錯誤,最后總結如下步驟,解決問題
- 使用老版本方式會出現(xiàn)如下報錯,本小結解決了該問題
mysql> update mysql.user set authentication_string=PASSWORD('123456') where User='root';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('123456') where User='root'' at line 1
強調:本小結以默認安裝路徑為準
- 停止MySQL服務
sudo /usr/local/mysql/support-files/mysql.server stop
- 禁止mysql驗證功能(先獲取管理員權限)
cd /usr/local/mysql/bin/
sudo su
./mysqld_safe --skip-grant-tables &
上述步驟后mysql會自動重啟
- 進入mysql重設密碼
./mysql
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '123456';
重置完成,exit退出再通過mysql -u root -p即可以新設密碼登陸。