macOs安装mysql

本文介绍在MacOS环境中通过brew安装MySQL的方法,并详细解释如何进行初始化设置,包括使用VALIDATE PASSWORD PLUGIN增强密码安全性。此外,针对安装后可能出现的连接问题提供了解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、macOS下安装myql

通过brew安装完mysql后执行以下命令

1.启动服务
mysql.server start
2.初始化
mysql_secure_installation
3.初始化设置说明
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 
//是否使用VALIDATE PASSWORD PLUGIN,这个看自己了

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(这里我选了1,即MEDIUM,密码需要有大小写字母、数字、特殊符号)
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) : (是否禁止root远程登录,根据自己的需求选择Y/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) : (是否删除test数据库,直接回车)

 ... skipping.
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) : (是否重新加载权限表,直接回车)

 ... skipping.
All done!

二、连接问题

在mac os环境下,安装了mysql之后出现连接不成功(第三方软件),通常是因为新版的mysql中新增了不同的密码加密机制,我们需要将加密机制改为旧版本的。

1.官网下载软件安装的情况

到系统偏好设置中找到mysql,到mysql服务中点击Initialize Database,勾选Use legacy password,重新启动服务,连接成功。

2.brew安装的情况

如果是通过brew安装的mysql,在系统偏好设置中找不到mysql图标,需要通过命令行来修改,linux系统中也遇到过同类型的问题

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'NewPassword@123456';

FLUSH PRIVILEGES;

这里设置密码很蛋疼,是因为mysql默认密码强度为中等强度。需要大小写、特殊字符、数字,可以先通过两个全局设置改变,而因为新旧版本的mysql密码教养规则不同,我们可以通过SHOW VARIABLES LIKE 'validate_password%';
来查看对应的规则是什么然后通过以下代码修改强度跟长度即可

set global validate_password.policy = 0
set global validate_password.length = 4

但是!我发现一开始初始化的时候,如果选择了使用VALIDATE PASSWORD PLUGIN插件并进行设置之后,再做修改似乎是没有效果的

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值