Mac 下 修改mysql root 密碼 和 新建用戶

mac下安裝mysql後,root密碼爲空,第一次登陸navicat正常,jdbc連接數據庫正常。第二天開發時,發現navicat登陸不上,jdbc連不上。

提示錯誤:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

之後得知,root用戶第一次登陸後需要修改密碼。

筆者之後按照網上教程嘗試多種方法都不能修改密碼,之後安裝workbench後,可以登陸mysql,但是不能修改和新增密碼。

提示如下:The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

最後結合多種方案,解決此問題。


-------華麗的分割線,具體方法如下----------------

1.安裝workbench

2.mac->系統偏好設置->點mysql 在彈出頁面中 stop mysql服務

3.進入終端

輸入:cd /usr/local/mysql/bin/

回車後 登錄管理員權限

sudo su

回車後輸入以下命令來禁止mysql驗證功能

 ./mysqld_safe --skip-grant-tables &

此時,workbench和navicat都可登陸mysql了。成功了一半。

4.打開workbench,連接mysql,點擊user and privileges,如下圖,選擇root用戶,修改密碼。


5.第4步中,若成功,則修改成功。若提示圖下錯誤:

The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement

則在mysql中逐步運行如下代碼:mysql> 

set global read_only=0;(關掉新主庫的只讀屬性)

 flush privileges;

set global read_only=1;(讀寫屬相)

 flush privileges;

6. 之後可以修改密碼了。


-------------華麗的分割線,拿走不謝---------------------

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章