查找并確定自己需要安裝的版本
brew search mysql
==> Formulae
automysqlbackup mysql-connector-c mysql@5.5
mysql mysql-connector-c++ mysql@5.6
mysql++ mysql-sandbox mysql@5.7 ?
mysql-client mysql-search-replace mysqltuner
mysql-cluster mysql-utilities
==> Casks
mysql-connector-python mysql-utilities navicat-for-mysql
mysql-shell mysqlworkbench sqlpro-for-mysql
安裝msyql@5.7
#指定版本安裝
brew install mysql@5.7
#配置環(huán)境變量
echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
#啟動(dòng)服務(wù)
mysql.server start
brew services start mysql@5.7
#初始化,設(shè)置密碼
mysql_secure_installation
[root@zhangMySQL5711 bin]# mysql_secure_installation
Enter password:
Securing the MySQL server deployment.
VALIDATE PASSWORD PLUGIN can be used to test passwords //密碼驗(yàn)證插件,為了提高安全性,需要驗(yàn)證密碼
and improve security. It checks the strength of password // 它會(huì)檢查密碼的強(qiáng)度
and allows the users to set only those passwords which are //只允許用戶設(shè)置足夠安全的密碼
secure enough. Would you like to setup VALIDATE PASSWORD plugin? //提示安裝密碼驗(yàn)證插件
Press y|Y for Yes, any other key for No: y
There are three levels of password validation policy: //三個(gè)等級(jí)的驗(yàn)證策略
LOW Length >= 8 //最小長(zhǎng)度大于等于8個(gè)字符
MEDIUM Length >= 8, numeric, mixed case, and special characters //數(shù)字,字母,特殊字符 混合,具體的應(yīng)該是至少1個(gè)數(shù)字,1個(gè)字母,1個(gè)特殊字符,長(zhǎng)度不超過32個(gè)字符
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file // 最嚴(yán)格,加上了,字典文件
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2 //這里我選擇2 MEDIUM
Using existing password for root.
Estimated strength of the password: 50 //這里也是密碼強(qiáng)度的評(píng)級(jí)
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
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 //插件驗(yàn)證不通過,不符合當(dāng)前安全要求級(jí)別
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, //默認(rèn)情況下,MySQL有一個(gè)匿名用戶,
allowing anyone to log into MySQL without having to have //這個(gè)匿名用戶,不必有一個(gè)用戶為他們創(chuàng)建,匿名用戶允許任何人登錄到MySQL,
a user account created for them. This is intended only for //這只是為了方便測(cè)試使用
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production //在正式環(huán)境使用的時(shí)候,建議你移除它
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 //一般情況下,root用戶只允許使用"localhost"方式登錄,
'localhost'. This ensures that someone cannot guess at // 以此確保,不能被某些人通過網(wǎng)絡(luò)的方式訪問
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 //默認(rèn)情況下,MySQL數(shù)據(jù)庫(kù)中有一個(gè)任何用戶都可以訪問的test庫(kù),
anyone can access. This is also intended only for testing, //這也僅僅是為了測(cè)試
and should be removed before moving into a production // 在正式環(huán)境下,應(yīng)該移除掉
environment.
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 //刷新權(quán)限表,以確保所有的修改可以立刻生效
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!
啟動(dòng)服務(wù)
mysql.server start
brew services start mysql@5.7
停止服務(wù)
mysql.server stop
brew services stop mysql@5.7