Mac下使用 brew 安装mysql

一、打开mac控制台

brew install [email protected] 
 修改环境变量
vi ~/.zshrc

export PATH=${PATH}:/usr/local/Cellar/[email protected]/5.7.24/bin

source ~/.zshrc

二、启动mysql服务

mysql.server start

三、初始化mysql配置

mysql_secure_installation
WXiangQianMacBook-Pro:~ wxq$ mysql_secure_installation

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: N   // 这个选yes的话密码长度就必须要设置为8位以上,但我只想要6位的
Please set the password for root here.

New password:             // 设置密码

Re-enter new password:     // 再一次确认密码
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) : n  //不接受root远程登录账号

 ... 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) : y  //删除text数据库
 - 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!

设置密码时提示:ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number;

使用其他语句时, 总是会提示 ERROR 1820 (HY000): You must SET PASSWORD before executing this statement. 意思就是说必须先设置一个密码

而设定密码时又提示 ERROR 1372 (HY000): Password hash should be a 41-digit hexadecimal number ;

这是因为 你输入的密码是明文, 不允许这么输入. 可以在其他已安装过mysql的终端使用 select password('你想输入的密码');查询出你的密码对应的字符串, 然后用这个字符串替换你的密码.

这样mysql就安装成功了

mysql -u root -p  输入密码以后i就可以正常进入了

启动使用MySQL 使用如下命令:

# 启动 mysql, 并设置为开机启动
brew services start mysql
# 关闭 mysql
brew services stop mysql
# 重启 mysql
brew services restart mysql

出现上面的问题时,使用重启 mysql brew services restart mysql 即可解决! 重启后等待一会。

发布了76 篇原创文章 · 获赞 112 · 访问量 7万+

猜你喜欢

转载自blog.csdn.net/qq175023117/article/details/88994475
今日推荐