mac下安装mysql5.7

时间:2022-02-28 02:05:05

自己mac电脑安装mysql,这里记录下,方便后面升级mysql或遇到版本兼容问题作出排查.

#搜索查看可用版本
# tk @ MacBook-Pro in ~/www/l_project on git:test x [16:26:44] C:1
$ brew search mysql
==> Formulae
automysqlbackup          mysql-client             mysql-connector-c        mysql-utilities          [email protected]5.7
mysql                    mysql-cluster            mysql-sandbox            [email protected]5.5                mysqltuner
mysql                    mysql-connector-c        mysql-search-replace     [email protected]5.6

==> Casks
mysql-connector-python                   mysql-utilities                          navicat-for-mysql
mysql-shell                              mysqlworkbench                           sqlpro-for-mysql


# tk @ MacBook-Pro in ~/www/l_project on git:test x [16:28:15] 
$ brew install [email protected]5.7
Warning: You are using macOS 10.15.
We do not provide support for this pre-release version.
You will encounter build failures with some formulae.
Please create pull requests instead of asking for help on Homebrews GitHub,
Discourse, Twitter or IRC. You are responsible for resolving any issues you
experience, as you are running this pre-release version.

==> Downloading https://homebrew.bintray.com/bottles/[email protected]
==> Downloading from https://akamai.bintray.com/81/815ae8aa8c765f57e806ff9197eaa5783b138c493d68333c553b25f441b6af3e?__gda__
######################################################################## 100.0%
==> Pouring [email protected]5.7-5.7.26.mojave.bottle.tar.gz
==> /usr/local/Cellar/[email protected]5.7/5.7.26/bin/mysqld --initialize-insecure --user=tankun --basedir=/usr/local/Cellar/[email protected]5.7
==> Caveats
Weve installed your MySQL database without a root password. To secure it run:
    mysql_secure_installation

MySQL is configured to only allow connections from localhost by default

To connect run:
    mysql -uroot

[email protected]5.7 is keg-only, which means it was not symlinked into /usr/local,
because this is an alternate version of another formula.

If you need to have [email protected]5.7 first in your PATH run:
  echo export PATH="/usr/local/opt/[email protected]/bin:$PATH" >> ~/.zshrc

For compilers to find [email protected]5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/[email protected]/lib"
  export CPPFLAGS="-I/usr/local/opt/[email protected]/include"


To have launchd start [email protected]5.7 now and restart at login:
  brew services start [email protected]5.7
Or, if you dont want/need a background service you can just run:
  /usr/local/opt/[email protected]5.7/bin/mysql.server start
==> Summary
??  /usr/local/Cellar/[email protected]5.7/5.7.26: 320 files, 231.8MB
==> `brew cleanup` has not been run in 30 days, running now...
Removing: /Users/tk/Library/Caches/Homebrew/lrzsz--0.12.20_1.mojave.bottle.tar.gz... (156KB)
Removing: /Users/tk/Library/Caches/Homebrew/Cask/docker--2.0.0.3-ce-mac81,31259.dmg... (521.5MB)
Removing: /Users/tk/Library/Logs/Homebrew/telnet... (64B)


#按照安装提示依次执行
# tk @ MacBook-Pro in ~/www/l_project on git:test x [16:33:19] C:127
$ echo export PATH="/usr/local/opt/[email protected]/bin:$PATH" >> ~/.zshrc

# tk @ MacBook-Pro in ~/www/l_project on git:test x [16:34:17] 
$ export LDFLAGS="-L/usr/local/opt/[email protected]/lib"

# tk @ MacBook-Pro in ~/www/l_project on git:test x [16:34:43] 
$  export CPPFLAGS="-I/usr/local/opt/[email protected]/include"

#启动mysql用,暂时用不上
#brew services start [email protected]5.7

#创建软链
# tk @ MacBook-Pro in ~/www/l_project on git:test x  [16:50:37] C:127
$ ln -s /usr/local/opt/[email protected]5.7/bin/mysql /usr/local/bin/mysql

#查看mysql版本
# tk @ MacBook-Pro in ~/www/l_project on git:test x [17:39:26] 
$ mysql -V
mysql  Ver 14.14 Distrib 5.7.26, for osx10.14 (x86_64) using  EditLine wrapper