注意⚠️:本教程是采用Homebrew安装mysql,引用官方的一句话:Homebrew是Mac OS 不可或缺的套件管理器。执行一下命令即可安装Homebrew:
# 安装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
- 使用Homebrew搜索mysql版本
% 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
- 安装mysql@5.7
% 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. 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
- 启动MySQL服务
% mysql.server start
Starting MySQL
. SUCCESS!
- MySQL初始化配置
% mysql_secure_installation
- 登陆测试
评论区