MAC安裝MYSQL

安裝 Homebrew 安裝工具

官網 https://brew.sh/index_zh-cn 

輸入下面命令去終端,然後按任意鍵繼續

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

開始用命令安裝MYSQL 示例如下

安裝mysql:brew install mysql

如果初始化出錯,可能需要加軟連接 修改安裝目錄下的my.cnf文件 加入下面配置,mysql.sock存放路徑不一樣,可以find 先查找

socket  = /private/tmp/mysql.sock
feideMacBook-Air:~ fei$ brew install [email protected]
Updating Homebrew...
==> Downloading https://homebrew.bintray.com/bottles/[email protected]_sierra.
Already downloaded: /Users/fei/Library/Caches/Homebrew/[email protected]_sierra.bottle.tar.gz
==> Pouring [email protected]_sierra.bottle.tar.gz
==> /usr/local/Cellar/[email protected]/5.7.23/bin/mysqld --initialize-insecure --user=fei
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

This formula is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have this software first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

For compilers to find this software you may need to set:
    LDFLAGS:  -L/usr/local/opt/[email protected]/lib
    CPPFLAGS: -I/usr/local/opt/[email protected]/include


To have launchd start [email protected] now and restart at login:
  brew services start [email protected]
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/[email protected]/bin/mysql.server start
==> Summary
🍺  /usr/local/Cellar/[email protected]/5.7.23: 317 files, 234.4MB

基本都是brew工具提示操作 

對mysql進行初始化操作:mysql_secure_installation

初始化之前必須啓動服務 命令如下 

mysql.server start
或者是
啓動mysql:brew services start [email protected]
停止mysql:brew services stop [email protected]
cometdeMacBook-Pro:~ comet
$ 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?
 // 這個選yes的話密碼長度就必須要設置爲8位以上,但我只想要6位的
Press y|Y for Yes, any other key for No: N   
Please set the password for root here.
 
New password:            // 設置密碼
 
Re-enter new password:     // 再一次確認密碼
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.
 //是否禁止遠程登錄
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
 
 ... 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庫
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - 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.
 
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.
 
All done!

到這裏安裝完成,下面嘗試登錄

登陸mysql:mysql -u root -p
啓動mysql:brew services start [email protected]
停止mysql:brew services stop [email protected]

 

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