mac brew install mysql 报错_mac使用brew安装mysql

1、安装mysql

#brew install mysql复制代码

报错

Error: The following directories are not writable by your user:

/usr/local/lib

You should change the ownership of these directories to your user.

sudo chown -R $(whoami) /usr/local/lib复制代码

意思是 您应该将这些目录的所有权更改为您的用户

执行以下命令设置权限

#sudo chown -R wuj /usr/local/lib复制代码

然后重新安装即可 brew install mysql

2、启动mysql服务

#mysql.server start复制代码

3、设置密码

通过brew安装后默认密码为空

执行以下命令设置密码

#mysql_secure_installation复制代码

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

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、1、2选择一个

因为手误我选择了1,但在后面设置密码时无法设置简单密码

Estimated strength of the password: 25

Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y

... Failed! Error: Your password does not satisfy the current policy requirements复制代码

解决 更改密码强度为 LOW

先登录mysql

#mysql -uroot复制代码

设置validate_password_policy为0(表示等级low)

set global validate_password_policy=0;复制代码

执行会报错

ERROR 1193 (HY000): Unknown system variable 'validate_password_policy'复制代码

原因是 MySQL 5.7和MySQL 8.0版本变量名不同 validate_password_policy是在版本 MySQL 5.7中 存在 ,而 MySQL 8.0不存在

解决,执行以下命令查看密码验证插件

SHOW VARIABLES LIKE 'validate_password%';复制代码

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复制代码

可以看到在mysql8.0中 变量名 为 validate_password.policy

好了,修改变量名后执行设置成功

set global validate_password.policy=0;复制代码

除此之外 ,还需设置密码长度(默认是长度8位以上)

set global validate_password.length=4;复制代码

解决以上问题后再次执行以下命令,设置密码即可

#mysql_secure_installation复制代码

4、mysql登录验证

#mysql -uroot -p复制代码

显示数据库

#show databases;复制代码

另:

在php连接数据库时报错,无法连接到数据库

The server requested authentication method unknown to the client复制代码

发现是因为mysql8.0版本的问题

打开mysql数据库 -》用户-》编辑root用户修改

修改插件 caching_sha2_password为 mysql_native_password即可

参考

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值