1. 程式人生 > >4、【資料庫技術】Mac OS安裝MySQL

4、【資料庫技術】Mac OS安裝MySQL

Mac OS安裝MySQL

    在Mac環境下安裝MySQL有很多中選擇,可以去MySQL官網下載相應的安裝自己安裝,也可以使用Homebrew這樣的包管理工具進行安裝。推薦使用Homebrew進行安裝,具體的安裝步驟如下:

1、安裝Homebrew,Homebrew的安裝及簡單的操作參見我的另一篇部落格:https://mp.csdn.net/mdeditor/84956361#
2、brew doctor確認brew在正常工作(執行這條命令會彈出一些warning資訊,可以不去管他)
3、brew update更新Homebrew
4、brew install mysql 安裝mysql
5、mysql.server start 啟動mysql服務(mysql.server stop 關閉mysql服務)
6、執行mysql_secure_installation完成相關的配置,如下所示(其中有註釋的地方都是需要自己手動填寫的,需要注意一下):
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and
allows the users to set only those passwords which are //這裡時提醒你設定密碼 secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: y There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and
special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file // 這裡提示選一個密碼強度等級 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 Please set the password for root here. // 然後按照所選的密碼強度要求設定密碼 New password: Re-enter new password: Estimated strength of the password: 50 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y ... Failed! Error: Your password does not satisfy the current policy requirements //嘗試了一下,選擇0或者1都會顯示這條錯誤,讓你再次設定密碼,建議設定一個稍微複雜一些的密碼 New password: Re-enter new password: Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. // 這裡刪除預設無密碼使用者 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. // 禁止遠端root登入,我選的是禁止,不管自己的電腦上有沒有敏感資訊,都需要養成這樣的安全意識,哈哈哈 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y By default, MySQL comes with a database named 'test’ that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. // 這裡刪除預設自帶的test資料庫 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : n ... skipping. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
7、好了,使用Homebrew安裝配置mysql完畢,下面測試一下:

先啟動mysql服務:

mysql.server start

登陸mysql:

mysql -u root -p

會提示你輸入密碼,就是在上面執行mysql_secure_installation命令後你設定的密碼;

最後,使用完畢後記得停止mysql服務:

mysql.server stop