mac上使用Homebrew安装mysql

注意⚠️:本教程是采用Homebrew安装mysql,引用官方的一句话:Homebrew是Mac OS 不可或缺的套件管理器。执行一下命令即可安装Homebrew:

1
2
3
4
5
6
7
# 安装Homebrew
/usr/bin/ruby -e "$(curl -fsSL https://cdn.jsdelivr.net/gh/ineo6/homebrew-install/install)"
# 查看版本信息
% brew -v
# 出现下面版本信息,则表明安装成功
Homebrew 3.3.4
Homebrew/homebrew-core (git revision 4605f7a940f; last commit 2021-11-21)

安装mysql

  1. 使用Homebrew搜索mysql版本
1
2
3
4
5
6
7
8
9
10
11
% brew search mysql

==> Formulae
automysqlbackup mysql-client mysql-sandbox mysql@5.7
mysql mysql-client@5.7 mysql-search-replace mysqltuner
mysql++ mysql-connector-c++ mysql@5.6 qt-mysql

==> Casks
homebrew/cask/mysql-connector-python homebrew/cask/navicat-for-mysql
homebrew/cask/mysql-shell homebrew/cask/sqlpro-for-mysql
homebrew/cask/mysql-utilities
  1. 安装mysql@5.7
1
2
3
4
5
6
7
8
9
10
11
% brew install mysql@5.7

==> Downloading https://ghcr.io/v2/homebrew/core/mysql/5.7/manifests/5.7.36
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/mysql/5.7/blobs/sha256:e23df0f6e8bfc83fe2e982ec60e8
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sha256:e23df0f6e8bfc83
######################################################################## 100.0%
==> Pouring mysql@5.7--5.7.36.arm64_big_sur.bottle.tar.gz
==> /opt/homebrew/Cellar/mysql@5.7/5.7.36/bin/mysqld --initialize-insecure --user=hyunmin --basedir=
==> Caveats
...
  1. 配置环境变量
1
2
3
4
5
6
7
8
9
10
11
# 1. bash shell
% vim ~/.bash_profile
# 2. zsh shell
% vim ~/.zshrc

# 在配置文件中加入
export PATH="/opt/homebrew/opt/mysql@5.7/bin:$PATH"

% source ~/.bash_profile
#
% source ~/.zshrc

  1. 启动MySQL服务
1
2
3
4
% mysql.server start

Starting MySQL
. SUCCESS!
  1. MySQL初始化配置
1
% mysql_secure_installation

  1. 登陆测试