關(guān)于brew的使用教程就不再贅述,下面主要講一下怎樣使用brew安裝Mysq
1.打開(kāi)terminal也就是我們所的命令窗口
2.運(yùn)行brew search mysql,我們可以看到Mysql相關(guān)軟件
automysqlbackup mysql++ mysql-cluster mysql-connector-c++ mysql-search-replace
mysql@5.5 mysql@5.7 mysql mysql-client mysql-connector-c mysql-sandbox
mysql-utilities mysql@5.6 mysqltuner
==> Casks
homebrew/cask/mysql-connector-python homebrew/cask/mysql-shell
homebrew/cask/mysql-utilities homebrew/cask/navicat-for-mysql
homebrew/cask/sqlpro-for-mysql
3.我們可以選擇安裝的版本,也可以粗暴的用命令brew install mysql安裝最新版
==> Installing dependencies for mysql: openssl
==> Installing mysql dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2p.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.2p.mojave.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
==> Summary
?? /usr/local/Cellar/openssl/1.0.2p: 1,793 files, 12MB
==> Installing mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-8.0.12.mojave.bottle.tar.gz
######################################################################## 100.0%
==> Pouring mysql-8.0.12.mojave.bottle.tar.gz
==> /usr/local/Cellar/mysql/8.0.12/bin/mysqld --initialize-insecure --user=chenjianyuan --basedir=/usr/local/Cellar/mysql/8.0.12 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> 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
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/8.0.12: 255 files, 233.0MB
==> Caveats
==> openssl
A CA file has been bootstrapped using certificates from the SystemRoots
keychain. To add additional certificates (e.g. the certificates added in
the System keychain), place .pem files in
/usr/local/etc/openssl/certs
and run
/usr/local/opt/openssl/bin/c_rehash
openssl is keg-only, which means it was not symlinked into /usr/local,
because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
If you need to have openssl first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
For compilers to find openssl you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
==> mysql
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
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
安裝過(guò)程會(huì)輸出一些配置以及命令相關(guān)信息。
4.輸入命令mysql.server start 啟動(dòng)Mysql
5.配置Mysql,最簡(jiǎn)單的方法就是使用使用mysql的配置腳本/usr/local/opt/mysql/bin/mysql_secure_installation啟動(dòng)這個(gè)腳本,即可根據(jù)如下命令提示進(jìn)行初始化設(shè)置
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT 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 component?
Press y|Y for Yes, any other key for No: y //使用密碼驗(yàn)證
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: 0 // 選擇密碼驗(yàn)證等級(jí)
Please set the password for root here.
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
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 // 是否禁止遠(yuǎ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.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y // 是否刪除測(cè)試庫(kù)
- 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 // 刷新數(shù)據(jù)庫(kù)權(quán)限
Success.
All done! // 完成
以上我們就完成了Mysql的安裝。