Mac上使用brew安装MySQL

Author Avatar
Reborn 7月 26, 2018
  • 在其它设备中阅读本文章

参考:https://segmentfault.com/q/1010000000475470

安装

brew install mysql

开启MySQL

通过brew

brew services start mysql

mysql.server start

使用MySQL的配置脚本(MySQL 提供的配置向导)

mysql_secure_installation
# 完整路径
/usr/local/opt/mysql/bin/mysql_secure_installation

启动这个脚本后,即可根据如下命令提示进行初始化设置:

$ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

# 输入当前root密码,一般为空
Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

# 首次使用自带配置脚本,设置root密码
Set root password? [Y/n] y 
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


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? [Y/n] 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? [Y/n] y
 ... Success!

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? [Y/n] 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? [Y/n] y
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

5.6版本和8.0版本的有点不一样,8.0版似乎有个密码安全检测插件。
下面是8.0版本的:

$ mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.
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?

# 是否采用mysql密码安全检测插件(这里我选择了是,密码检查插件要求密码复杂程度高,大小写字母+数字+字符等)
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: 2

# 首次使用自带配置脚本,设置root密码
Please set the password for root here. 

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.

#  是否禁止远程登录
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Success.

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
 - 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

brew services stop mysql