使用Homebrew安装MySQL

本文介绍了在macOS系统中使用Homebrew进行软件安装的方法。首先说明了Homebrew的安装与验证,接着介绍了其图形化工具Cakebrew的安装。然后通过Cakebrew安装mysql 5.7,并配置其环境变量,最后启动并初始化mysql,完成整个安装配置流程。

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

Homebrew

Homebrew 是 macOS 系统自带的包管理器,类似于 CentOS 中的 yum 和 Ubuntu 的 apt-get

安装Homebrew

目前高版本的 macOS 系统中已经安装好了 Homebrew,输入

brew doctor
复制代码

验证

如果你的系统没有安装,输入以下命令 安装Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
复制代码

安装完成之后

  1. 输入brew doctor 确认 brew 能正常工作
  2. 输入brew update 更新包

安装 Cakebrew

Cakebrew 是 Homebrew 的一个图形化工具,可以更加直观对 Homebrew 进行管理,推荐安装

安装也很简单去 www.cakebrew.com/ 这个网站下载安装包进行安装就行了,软件自带中文。

接下来就可以愉快的玩耍了

安装软件时可能会遇到没有权限访问目录的问题,可以按照 Cakebrew 的提示在终端输入以下命令

sudo chown -R wqlm /usr/local/share/man/man8
复制代码
  • chown 命令是将 指定文件或目录的拥有者 改为指定的用户或组
  • -R 是循环遍历 指定目录及子目录
  • wqlm 是我系统的用户名
  • /usr/local/share/man/man8 是被指定的目录

通过 Cakebrew 安装 mysql

安装 mysql 5.7

如图,输入你要安装的软件,选择其中一个,点击上方的安装按钮,就开始安装了,由于我已经安装了 msyql@5.7 所以上面显示的是卸载

配置 msyql 的环境变量

安装完之后我们需要配置 msyql 的环境变量

  1. 切换到用户目录下cd ~
  2. 编辑 .bash_profile 配置文件 vi .bash_profile
  3. 输入i 切换到编辑模式
  4. 输入export PATH=/usr/local/opt/mysql@5.7/bin:$PATH ,/usr/local/opt/mysql@5.7/是你的安装目录
  5. 按下Esc输入:wq,保存并退出vi编辑器
  6. 输入source .bash_profile使配置立即生效

启动并初始化msyql

启动mysql服务

sudo mysql.server start

初始化mysql

sudo 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?
# 上面的意思是说你十分要为root设置密码,选择 y
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
# 这里要你选一个密码强度等级,0表示LOW,只要求你的密码长度大于8,由于我只是在本地玩玩,选择0
Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0

Please set the password for root here.
# 按照所选的密码强度要求 设定密码
New password:
# 再次输入密码
Re-enter new password:

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
# 如果你的密码没有满足 你所选的密码强度要求,它会让你重写设定密码
New password:
Re-enter new password:

Estimated strength of the password: 100
# 确认使用该密码吗,选择 y
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
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.
# 禁止远程root登录,我选的是no。因为我只是本地玩玩不会用于生产,也不会存什么敏感数据
Disallow root login remotely? 
(Press y|Y for Yes, any other key for No) : no

 ... 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.

# 要删除默认自带的test数据库吗,我选择 no
Remove test database and access to it? 
(Press y|Y for Yes, any other key for No) : no

 - 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.
# 是否让配置立即生效,选择 y
Reload privilege tables now? 
(Press y|Y for Yes, any other key for No) : y

Success.
All done!
复制代码

设置完成之后,就可以通过 root 和刚刚设置的密码登陆mysql了

mysql -u root -p
复制代码

转载于:https://juejin.im/post/5ce0dc7ef265da1ba2522e98

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值