目录
- (1)准备工作
- 1.1 更新 brew
- (2)正式安装
- 2.1 安装MySQL:
- 2.2 启动mysql
- (3)初始化数据库
- 3.1 选择验证密码组件
- 3.2 密码强度
- 3.3 删除匿名用户
- 3.4 禁用root用户远程连接
- 3.5 删除test数据库
- 3.6 重新载入权限表
(1)准备工作
1.1 更新 brew
更新Homebrew的库:
brew update
(2)正式安装
2.1 安装MySQL:
brew install mysql
2.2 启动mysql
brew services start mysql
(3)初始化数据库
官方建议刚安装好数据库的时候都要初始化数据,因为这样数据库会更加安全
mysql_secure_installation
3.1 选择验证密码组件
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,我输入的 y
3.2 密码强度
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.
有三种密码强度的策略
低级密码:密码长度大于等于8
中级密码:密码长度大于等于8,并且是数字,大小写混合,特殊字符
强密码:密码长度大于等于8,并且数字,大小写混合,特殊字符和字典文件
我选择的是1,中级密码强度,输入完之后会再输入root密码
3.3 删除匿名用户
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.
MySQL安装默认具有匿名用户,允许任何人登录MySQL,而无需为他们创建的用户帐户。这仅适用于测试,并使安装过程更加顺利。在进入生产之前,您应该删除它们环境。
一般选择 y
3.4 禁用root用户远程连接
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.
通常,只允许root连接“本地主机”。这确保了别人不能通过网络访问你的root用户,我是本地安装的 mysql,因此就选择y,就是不允许root用户远程连接
3.5 删除test数据库
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.
默认情况下,MySQL附带了一个名为“test”的数据库,任何人都可以访问。这也仅用于测试,在投入生产之前,应将其删除。
我选择的删除这个test库
3.6 重新载入权限表
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!
重新加载权限表将确保迄今为止所做的所有更改立即生效。
选择y,之后就会重新刷新权限,至此mysql就安装完成了