mac下MySQL修改root初始密碼

        新裝的mysql在登錄時需要注意:

For example, if you run the server using the mysql login account, you should log in as mysql before using the instructions. Alternatively, you can log in as root, but in this case you must start mysqld with the --user=mysql option. If you start the server as root without using --user=mysql, the server may create root-owned files in the data directory, such as log files, and these may cause permission-related problems for future server startups.
(以上內容來自官方文檔)

在使用root用戶登錄時,需要加上--user=mysql,否則服務器將會在數據目錄下洗創建一個root-owned文件,這樣在服務器啓動的時候會引起權限問題。(未嘗試--user=mysql,新裝完mysql的同學可以嘗試下)

        現在到這裏,已經登錄不了mysql了,要麼是ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO),

要麼是ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password:  YES),現在如何做?

        在終端下輸入:cd /usr/local/mysql/bin/

        使用管理員權限:sudo su

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

        ./mysqld_safe --skip-grant-tables &

        之後mysql會自動重啓,完成之後打開mysql workbench,在Query窗口執行flush privileges,再執行set password for root='<your password>',執行完之後,就可以使用新的root密碼來登錄mysql了。


發佈了150 篇原創文章 · 獲贊 7 · 訪問量 28萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章