MacOs安裝mysql與修改root密碼

來源:互聯網
上載者:User

標籤:round   賬戶   span   www.   mon   body   port   info   /usr   

1、下載安裝包

http://www.mysql.com/downloads/ 

找到如下內容下載

mysql-5.7.21-1-macos10.13-x86_64.dmg是

https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.21-1-macos10.13-x86_64.dmg

2、下載後按提示安裝

按照一路安裝步驟,儲存最後彈出框裡的mysql root密碼。

3、安裝好之後,還需要啟動

開啟設定並且點擊MySql開啟MySql伺服器,根據需要是否開機自啟

4、設定環境變數

此時我們在終端輸入此時我們在命令列輸入mysql -uroot -p命令會提示沒有commod not found,我們還需要將mysql加入系統內容變數。

(1).進入/usr/local/mysql/bin,查看此目錄下是否有mysql。

(2).執行vim ~/.bash_profile

在該檔案中添加mysql/bin的目錄,:

PATH=$PATH:/usr/local/mysql/bin

添加完成後,按esc,然後輸入wq儲存。

最後在命令列輸入source ~/.bash_profile

5、由於我忘記了密碼,這一步是mac下修改mysql的密碼

命令列起停mysql:

都得用root賬戶

yuchaodeMacBook-Pro:support-files root# ./mysql.server start 
                                 a/ stop / status /restartStarting MySQL.Logging to ‘/usr/local/mysql/data/yuchaodeMacBook-Pro.local.err‘. SUCCESS! yuchaodeMacBook-Pro:support-files root# ./mysql.server stop Shutting down MySQL. SUCCESS!
yuchaodeMacBook-Pro:support-files root# pwd
/usr/local/mysql/support-files

6、如果有報錯沒有pid檔案

刪除/usr/local/mysql/data/*.err

7、跳過授權表,修改密碼ps aux |grep mysql

#這一步,必須關閉mysql!!!!!!跳過許可權驗證
yuchaodeMacBook-Pro:bin root# ./mysqld_safe --skip-grant-tables &

#直接用root登陸,不要求輸入密碼
./mysql -uroot

#修改密碼
mysql>
update mysql.user set authentication_string =password(‘redhat‘) where User=‘root‘;

#重新整理表
flush privileges;

#重啟mysql服務,會自動關閉跳過授權表的進程!!
yuchaodeMacBook-Pro:bin root# ../support-files/mysql.server restart

8、大功告成!!!!!!!!!!!!!!!!!!!!!!!!!

 

MacOs安裝mysql與修改root密碼

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.