安裝命令:
brew install mysql
安裝完成之后,啟動mysql:
mysql.server start
發現無此命令:
command not found
首先,檢查是否是安裝了。重新執行一遍:
brew install mysql
提示:
Warning: mysql-5.7.17 already installed, it's just not linked
然后網上查找解決方法,執行:
brew link --overwrite mysql
報錯:
Linking /usr/local/Cellar/mysql/5.7.17...
Error: Could not symlink share/man/man8/mysqld.8 /usr/local/share/man/man8 is not writable.
查找解決方法,以下語句執行成功:
sudo chown -R 'username' /usr/local
解決了問題后,重新執行:
brew link --overwrite mysql
提示:
Linking /usr/local/Cellar/mysql/5.7.17... 93 symlinks created
重新執行:
mysql.server start
沒有錯誤。表示這時我們已經啟動mysql服務器,按照brew的提示設置管理員密碼。
mysql_secure_installation
然后根據提示操作就好了,以下代碼來自文獻[1]。
1 Securing the MySQL server deployment. 2 3 Connecting to MySQL using a blank password. 4 5 VALIDATE PASSWORD PLUGIN can be used to test passwords 6 and improve security. It checks the strength of password 7 and allows the users to set only those passwords which are 8 secure enough. Would you like to setup VALIDATE PASSWORD plugin? 9 10 Press y|Y for Yes, any other key for No: y 11 12 There are three levels of password validation policy: 13 14 LOW Length >= 8 15 MEDIUM Length >= 8, numeric, mixed case, and special characters 16 STRONG Length >= 8, numeric, mixed case, special characters and dictionary file 17 // 這里提示選一個密碼強度等級 18 Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 19 Please set the password for root here. 20 // 然后按照所選的密碼強度要求設定密碼 21 New password: 22 23 Re-enter new password: 24 25 Estimated strength of the password: 50 26 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y 27 ... Failed! Error: Your password does not satisfy the current policy requirements 28 29 New password: 30 31 Re-enter new password: 32 33 Estimated strength of the password: 100 34 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y 35 By default, a MySQL installation has an anonymous user, 36 allowing anyone to log into MySQL without having to have 37 a user account created for them. This is intended only for 38 testing, and to make the installation go a bit smoother. 39 You should remove them before moving into a production 40 environment. 41 // 這里刪除默認無密碼用戶 42 Remove anonymous users? (Press y|Y for Yes, any other key for No) : y 43 Success. 44 45 46 Normally, root should only be allowed to connect from 47 'localhost'. This ensures that someone cannot guess at 48 the root password from the network. 49 // 禁止遠程root登錄,我選的是不禁止。因為我的mac上的數據庫不會放到公網上,也不會存什么敏感數據 50 Disallow root login remotely? (Press y|Y for Yes, any other key for No) : no 51 52 ... skipping. 53 By default, MySQL comes with a database named 'test' that 54 anyone can access. This is also intended only for testing, 55 and should be removed before moving into a production 56 environment. 57 58 // 這里刪除默認自帶的test數據庫 59 Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y 60 - Dropping test database... 61 Success. 62 63 - Removing privileges on test database... 64 Success. 65 66 Reloading the privilege tables will ensure that all changes 67 made so far will take effect immediately. 68 69 Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y 70 Success. 71 72 All done!
執行:
mysql -r root -p
輸入密碼,成功進入:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.17 Homebrew
測試一下:
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.03 sec)
全部👌 !
參考文獻:
[1]http://blog.csdn.net/lkxlaz/article/details/54580735
[2]http://blog.csdn.net/wdsdsdsds/article/details/51983453
