Mac OSX 10.11 通过 HomeBrew 安装 MySQL

阿里云产品限时红包,最高 ¥1888 元,立即领取

在 Mac OSX 升级到 EICapitan 之后,原来安装的 MySQL 就多多少少出现了问题。于是决定重装:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
$ brew install mysql
==> Installing dependencies for mysql: openssl
==> Installing mysql dependency: openssl
==> Downloading https://homebrew.bintray.com/bottles/openssl-1.0.2e_1.el_capitan
######################################################################## 100.0%
==> Pouring openssl-1.0.2e_1.el_capitan.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl/certs

and run
/usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, which means it was not symlinked into /usr/local.

Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

LDFLAGS: -L/usr/local/opt/openssl/lib
CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
🍺 /usr/local/Cellar/openssl/1.0.2e_1: 465 files, 11.9M
==> Installing mysql
==> Downloading https://homebrew.bintray.com/bottles/mysql-5.7.10.el_capitan.bot
######################################################################## 100.0%
==> Pouring mysql-5.7.10.el_capitan.bottle.2.tar.gz
==> /usr/local/Cellar/mysql/5.7.10/bin/mysqld --initialize-insecure --user=lfy -
==> Caveats
We've installed your MySQL database without a root password. To secure it run:
mysql_secure_installation

To connect run:
mysql -uroot

To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
Then to load mysql now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
Or, if you don't want/need launchctl, you can just run:
mysql.server start
==> Summary
🍺 /usr/local/Cellar/mysql/5.7.10: 12,677 files, 433.2M

直接使用 mysql -uroot,出现如下错误提示:

1
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock'

原因是 mysql 服务没有启动,故尝试 mysql.server start,结果如下,依然出错。

1
2
3
$ mysql.server start
Starting MySQL
. ERROR! The server quit without updating PID file (/usr/local/var/mysql/bogon.pid).

最终的处理方式是:

  1. 通过 mysqld 直接启动 mysql。
  2. 由于 HomeBrew 安装的 mysql 默认root账户没有设置密码,故按照提示输入 mysql_secure_installation 来设置密码。
  3. 设置完成以后,就可以正常操作 mysql 了。

HomeBrew 安装的 mysql 的数据存储位置为 /usr/local/var/mysql。 可以通过 find / -name databasename 的方式根据数据库名称找到具体位置。