brew install mysql on mac os 10.10

Step-by-step

brew remove mysql
brew cleanup
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
rm ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
sudo rm -rf /usr/local/var/mysql #删除全部数据库
brew install mysql
# Inject launch agent
unset TMPDIR
# Set up databases to run as your user account
mysql_install_db --verbose --user=`whoami` --basedir="$(brew --prefix mysql)" --datadir=/usr/local/var/mysql --tmpdir=/tmp

然后进行安全设置,注意下面命令中的 mysql 版本要和目前安装的版本一致

/usr/local/Cellar/mysql/5.5.10/bin/mysql_secure_installation

用下面的命令自动在系统启动的时候加载 mysql

# To have launchd start mysql at login:
ln -sfv /usr/local/opt/mysql/*plist ~/Library/LaunchAgents

# start
launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
# stop
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

下面两个命令可以给你提供很大的帮助

brew info mysql
mysql --help

配置 my.cnf

如果找不到 /etc/my.cnf 也不用怕,自己创建一个,然后复制如下内容即可

[client]
port = 3306
socket = /tmp/mysql.sock
default-character-set = utf8

[mysqld]
collation-server = utf8_unicode_ci
character-set-server = utf8
init-connect ='SET NAMES utf8'
max_allowed_packet = 64M
bind-address = 127.0.0.1
port = 3306
socket = /tmp/mysql.sock

How to Disable Strict SQL Mode in MySQL 5.7

先用 mysql --help 查看,发现 MySQL 从如下位置读取配置文件 /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

sudo cp $(brew --prefix mysql)/support-files/my-default.cnf ~/.my.cnf

编辑该文件添加如下

[mysqld]
sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

重启 MySQL

相关链接

如果觉得我的文章对您有用,请在支付宝公益平台找个项目捐点钱。 @Victor Oct 27, 2014

奉献爱心