步驟
- 安裝Homebrew,詳細步驟參見Homebrew官網(wǎng)。
brew doctor 確認brew在正常工作。
brew update 更新包。
brew install mysql 安裝mysql。
==> Downloading https://homebrew./bottles/mysql-5.7.17.sierra.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql-5.7.17.sierra.bottle.tar.gz
==> Using the sandbox
==> /usr/local/Cellar/mysql/5.7.17/bin/mysqld --initialize-insecure --user=liangze --basedir=/usr/local/Cellar/mysql/5.7.17 --datadir=/usr/local/var/mysql --t
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
To connect run:
mysql -uroot
To have launchd start mysql now and restart at login:
brew services start mysql
Or, if you don't want/need a background service you can just run:
mysql.server start
==> Summary
/usr/local/Cellar/mysql/5.7.17: 14,226 files, 444.4M
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
這里順帶提下一下,在網(wǎng)上有很多教程說要在安裝完mysql之后運行mysql_install_db --verbose --user= whoami--basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp ,我試了一下行不通,原因mysql官方已經(jīng)說了,看這段:
mysql_install_db is deprecated as of MySQL 5.7.6 because its functionality has been integrated into mysqld, the MySQL server. To initialize a MySQL installation, invoke mysqld with the –initialize or –initialize-insecure option. For more information, see Section 2.10.1.1, “Initializing the Data Directory Manually Using mysqld”. mysql_install_db will be removed in a future MySQL release.
大意就是說mysql_install_db這個功能已經(jīng)在MySQL 5.7.6下取消了,它的功能現(xiàn)在已經(jīng)集成在了mysqld里了。所以盡量不要直接在網(wǎng)上拿來主義,如果我們仔細看brew install mysql的安裝過程,看這句:
==> /usr/local/Cellar/mysql/5.7.17/bin/mysqld –initialize-insecure –user=liangze –basedir=/usr/local/Cellar/mysql/5.7.17 –datadir=/usr/local/var/mysql –t
說明brew已經(jīng)為我們安裝好了。我們接下來需要做的brew也已經(jīng)告訴我了,看這句:
We’ve installed your MySQL database without a root password. To secure it run:
mysql_secure_installation
5.
那么我們就按照brew的提示運行 mysql_secure_installation,運行后會報錯:
> mysql_secure_installation
Securing the MySQL server deployment.
Enter password for user root:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
莫慌,提示說找不到mysql.sock。原因是mysql進程還沒啟動。
6. 啟動mysql服務(wù)
mysql.server start
7.再運行
> mysql_secure_installation
發(fā)現(xiàn)成功執(zhí)行命令
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.
// 然后按照所選的密碼強度要求設(shè)定密碼
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
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登錄,我選的是不禁止。因為我的mac上的數(shù)據(jù)庫不會放到公網(wǎng)上,也不會存什么敏感數(shù)據(jù)
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數(shù)據(jù)庫
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.
|