MacOS brew安装MySQL

前言

因MBP大修数据全丢,使用 HomeBrew 重新安装MySQL,以此记录下。

Homebrew是一款Mac OS平台下的软件包管理工具,拥有安装、卸载、更新、查看、搜索等很多实用的功能。

安装流程

执行 「brew install mysql」等待安装完成

执行 「brew services list」查看安装的服务

1
2
3
Name  Status  User File
mysql stopped
redis stopped

执行 「brew services start mysql」开启mysql服务

执行 「mysql_secure_installation」初始化设置,因为之前已经设置过密码意外退出了

1
Enter password for user root:

输入第一次设置的密码

1
2
3
4
5
6
7
8
The 'validate_password' component is installed on the server.
The subsequent steps will run with the existing configuration
of the component.
Using existing password for root.

Estimated strength of the password: 50
# 修改密码
Change the password for root ? ((Press y|Y for Yes, any other key for No) :

执行「y」

1
New password:

输入新密码(需要符合第一次设置的策略规则)

1
Re-enter new password:

再次输入新密码

1
2
# 是否删除匿名用户
Remove anonymous users? (Press y|Y for Yes, any other key for No) :

执行 「y」

1
2
# 是否禁用远程连接
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :

执行「n」为了开发方便

1
2
# 是否删除测试数据表
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :

执行「y」

1
2
# 是否现在重新加载权限表
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

执行 「y」

1
All done!

这样就设置完成了可以用新密码登陆MySQL了

执行 「mysql -u root -p」

修改密码策略(简单密码)

进入mysql之后 执行「SHOW VARIABLES LIKE ‘validate_password%’;」

1
2
3
4
5
6
7
8
9
10
11
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password.check_user_name | ON |
| validate_password.dictionary_file | |
| validate_password.length | 8 |
| validate_password.mixed_case_count | 1 |
| validate_password.number_count | 1 |
| validate_password.policy | MEDIUM |
| validate_password.special_char_count | 1 |
+--------------------------------------+--------+

validate_password.length 密码最小长度

validate_password.mixed_case_count 最小混合大小写数

validate_password.number_count 最小数字数

validate_password.policy 策略级别 [LOW、MEDIUM、STRONG]

validate_password.special_char_count 最小特殊字符数

执行 「set global validate_password.policy=0;」 把策略级别设置为Low 这样只会检验 validate_password.length

执行 「show databases;」 展示所有数据库

执行「use mysql」选择数据库

执行 「ALTER USER ‘root‘@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘12345678’;」修改密码为12345678

卸载验证密码插件

执行 「UNINSTALL COMPONENT ‘file://component_validate_password’;」

重新安装执行 「INSTALL PLUGIN validate_password SONAME ‘validate_password.so’;」

执行「use mysql」选择数据库

执行 「ALTER USER ‘root‘@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘root’;」修改密码为12345678

执行「flush privileges;」立即生效