使用Homebrew安裝MySQL

Homebrew

Homebrew 是 macOS 系統自帶的包管理器,相似於 CentOS 中的 yum 和 Ubuntu 的 apt-getmysql

安裝Homebrew

目前高版本的 macOS 系統中已經安裝好了 Homebrew,輸入git

brew doctor
複製代碼

驗證github

若是你的系統沒有安裝,輸入如下命令 安裝Homebrewsql

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
複製代碼

安裝完成以後數據庫

  1. 輸入brew doctor 確認 brew 能正常工做
  2. 輸入brew update 更新包

安裝 Cakebrew

Cakebrew 是 Homebrew 的一個圖形化工具,能夠更加直觀對 Homebrew 進行管理,推薦安裝ruby

安裝也很簡單去 www.cakebrew.com/ 這個網站下載安裝包進行安裝就好了,軟件自帶中文。bash

接下來就能夠愉快的玩耍了curl

安裝軟件時可能會遇到沒有權限訪問目錄的問題,能夠按照 Cakebrew 的提示在終端輸入如下命令編輯器

sudo chown -R wqlm /usr/local/share/man/man8
複製代碼
  • chown 命令是將 指定文件或目錄的擁有者 改成指定的用戶或組
  • -R 是循環遍歷 指定目錄及子目錄
  • wqlm 是我係統的用戶名
  • /usr/local/share/man/man8 是被指定的目錄

經過 Cakebrew 安裝 mysql

安裝 mysql 5.7

如圖,輸入你要安裝的軟件,選擇其中一個,點擊上方的安裝按鈕,就開始安裝了,因爲我已經安裝了 msyql@5.7 因此上面顯示的是卸載ide

配置 msyql 的環境變量

安裝完以後咱們須要配置 msyql 的環境變量

  1. 切換到用戶目錄下cd ~
  2. 編輯 .bash_profile 配置文件 vi .bash_profile
  3. 輸入i 切換到編輯模式
  4. 在path中追加安裝路徑 PATH=/usr/local/opt/mysql@5.7/bin:$PATH ,/usr/local/opt/mysql@5.7/是你的安裝目錄
  5. 按下Esc輸入:wq,保存並退出vi編輯器
  6. 輸入source .bash_profile使配置當即生效

啓動並初始化msyql

啓動mysql服務

sudo mysql.server start

初始化mysql

sudo 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?
# 上面的意思是說你是否要爲root設置密碼,選擇 y
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
# 這裏要你選一個密碼強度等級,0表示LOW,只要求你的密碼長度大於8,因爲我只是在本地玩玩,選擇0
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

Please set the password for root here.
# 按照所選的密碼強度要求 設定密碼
New password:
# 再次輸入密碼
Re-enter new password:

Estimated strength of the password: 25
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
# 若是你設的密碼沒有知足 你所選的密碼強度要求,它會讓你重寫設定密碼
New password:
Re-enter new password:

Estimated strength of the password: 100
# 確認使用該密碼嗎,選擇 y
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.
# 刪除默認的匿名用戶嗎,選擇 y
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登陸,我選的是no。由於我只是本地玩玩不會用於生產,也不會存什麼敏感數據
Disallow root login remotely? 
(Press y|Y for Yes, any other key for No) : no

 ... skipping.
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數據庫嗎,我選擇 no
Remove test database and access to it? 
(Press y|Y for Yes, any other key for No) : no

 - Dropping test database...
Success.
 - Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
# 是否讓配置當即生效,選擇 y
Reload privilege tables now? 
(Press y|Y for Yes, any other key for No) : y

Success.
All done!
複製代碼

設置完成以後,就能夠經過 root 和剛剛設置的密碼登錄mysql了

mysql -u root -p
複製代碼
相關文章
相關標籤/搜索