mac使用brew安装启动mysql步骤

1.搜索mysql版本

brew search mysql 搜索一下版本,看一下自己要下载的版本。然后我下载的是mysql@5.7。

2.安装mysql

brew install mysql@5.7

3.环境变量配置

安装成功后brew会给配置环境变量的提示
在这里插入图片描述
在终端执行环境变量配置:

echo 'export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"' >> ~/.zshrc
export LDFLAGS="-L/opt/homebrew/opt/mysql@5.7/lib"
export CPPFLAGS="-I/opt/homebrew/opt/mysql@5.7/include"

如果要永久生效,就把下边两个export写到~/.bash_profile文件中

4.启动服务

brew services start mysql@5.7

在这里插入图片描述

5.设置密码

总结:
1.启动服务
2.执行安全配置
3.删除匿名帐号,放开远程连接,删除test测试库,重新加载权限表
4.测试连接

//输入命令
DIDI-C02G17HXQ05P:~ didi$ 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: yes  //输入yes表示设置密码

There are three levels of password validation policy:

//提示密码强度为 low、medium、strong 低中高三种
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: 2
Please set the password for root here.

//新密码(输入不可见)
New password:Qian123@@@
//再次确认
Re-enter new password: Qian123@@@

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.

//是否删除匿名用户,y表示yes 其他表示no(百度建议删除:在mysql刚刚被安装后,存在用户名、密码为空的用户。这使得数据库服务器有无需密码被登录的可能性。为消除隐患,将匿名用户删除。)
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

 ... 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) : n

 ... 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) : y
Success.

All done!

//测试数据库连接,输入命令mysql -uroot -p后输入设置的密码
DIDI-C02G17HXQ05P:~ didi$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.28 Homebrew

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

//查看表
mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

至此mysql安装成功,在系统中存在mysql。

参考链接

  1. Mac用brew安装mysql
  2. Mac电脑使用brew 下载mysql
Mac使用brew命令安装MySQL非常方便。首先,你需要安装Homebrew,你可以在Homebrew官网找到安装的命令。安装完Homebrew后,你可以使用brew命令来安装MySQL。具体的步骤如下: 1. 打开终端,输入以下命令来安装MySQL: ``` brew install mysql ``` 这将使用Homebrew安装MySQL。 2. 安装完成后,你需要启动MySQL并设置密码。可以使用以下命令来启动MySQL: ``` brew services start mysql ``` 或者 ``` mysql.server start ``` 3. 启动MySQL后,你需要设置密码。可以使用以下命令来设置密码: ``` mysql_secure_installation ``` 按照提示进行设置,包括输入密码和其他安全选项。 安装完成后,你就可以开始使用MySQL了。如果需要查看MySQL安装成功与否,可以在终端输入以下命令: ``` brew info mysql ``` 这将显示MySQL的配置信息。 总结一下,使用brew命令在Mac安装MySQL步骤如下: 1. 安装Homebrew。 2. 使用brew命令安装MySQL。 3. 启动MySQL并设置密码。 4. 验证MySQL安装成功。 希望对你有帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [brew 安装mysql (Mac OS)](https://blog.csdn.net/weixin_43850253/article/details/123271617)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *2* *3* [Macbrew安装mysql](https://blog.csdn.net/weixin_43748076/article/details/123829582)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值