mac安装mysql

参考链接

  1. 基本安装指导
  2. 修复安装指定版本的问题

安装说明

安装详情都是根据上述参考链接进行总结的。

安装命令

安装最新版本

brew install mysql

安装指定版本,比如5.7

brew install mysql@5.7

安装结果

安装的基本详情都会在返回结果里面体现,所以小白可以加强对返回结果的理解。

brew install mysql@5.7
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 1 tap (homebrew/core).
==> Updated Formulae
fs-uae
==> Downloading https://homebrew.bintray.com/bottles/mysql@5.7-5.7.26.mojave.bottle.tar.gz
==> Downloading from https://akamai.bintray.com/81/815ae8aa8c765f57e806ff9197eaa5783b138c493d68333c553b25f441b6af3e?__gda__=exp=1562923064~hmac=31bc462198d92c1629a8360acc4514c48c
######################################################################## 100.0%
==> Pouring mysql@5.7-5.7.26.mojave.bottle.tar.gz
==> /usr/local/Cellar/mysql@5.7/5.7.26/bin/mysqld --initialize-insecure --user=songzeyu --basedir=/usr/local/Cellar/mysql@5.7/5.7.26 --datadir=/usr/local/var/mysql --tmpdir=/tmp
==> Caveats
We've 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
mysql@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 mysql@5.7 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile
For compilers to find mysql@5.7 you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql@5.7/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql@5.7/include"
To have launchd start mysql@5.7 now and restart at login:
  brew services start mysql@5.7
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/mysql@5.7/bin/mysql.server start
==> Summary
��  /usr/local/Cellar/mysql@5.7/5.7.26: 320 files, 231.8MB

对上面命令进行提取

mysql连接

mysql -uroot

导入执行命令

echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

启动mysql服务

brew services start mysql@5.7
/usr/local/opt/mysql@5.7/bin/mysql.server start

如果默认安装了最新版本,需要降级,那么请参考

修复安装指定版本的问题

密码设置(暂未验证)

安装好之后,mysql 的 root 用户默认是空密码,首先设置密码:

mysql_secure_installation

​ 因为 mysql5.7 增加了密码验证,所以在执行上一步后,你会看到这条信息:

 Would you like to setup VALIDATE PASSWORD plugin?

意思就是是否安装密码验证插件,个人建议不安装,因为安装之后你只能设置一个非常复杂的密码,麻烦的很。所以此时要输入no,不安装。如果你已经选择了y,不要紧,你可以连接 mysql 终端之后,执行命令卸载该插件:

UNINSTALL PLUGIN validate_password;

卸载成功!现在再执行一次mysql_secure_installation,选择不加载密码验证插件,你就可以设置一个简单的密码啦!

连接mysql

安装上述命令安装成功后,验证是否成功:

mysql -u root 

!!!出现了意料之外的情况!!!

-bash: mysql: command not found

吓到了,接连试了好几次,还是同样的问题。

根据上述参考资料进行修复,解决方案如下:

brew link mysql@5.7 --force

执行上述命令后,回显如下:

> Linking /usr/local/Cellar/mysql@5.7/5.7.23... 87 symlinks created

>  If you need to have this software first in your PATH instead consider running:
>  echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

意思就是让你执行下面命令

 echo 'export PATH="/usr/local/opt/mysql@5.7/bin:$PATH"' >> ~/.bash_profile

再次执行连接命令

mysql -u root 

连接成功

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 43
Server version: 5.7.26 Homebrew

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

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>

启动mysql的命令:

mysql.server start
brew services start mysql@5.7
posted @ 2019-07-13 16:53  jaspersong  阅读(631)  评论(0编辑  收藏  举报