Mac本地機器不配置好MYSQL,很多服務沒法跑起來厦幅,數(shù)據(jù)庫基本上是代碼最底層依賴;相比較而言慨飘,web服務起不起來對開發(fā)效率的影響反而沒那么大确憨;
1 Mac 上的MYSQL 配置文件在哪译荞?
默認沒有my.cnf 文件,但是可以創(chuàng)建一個
執(zhí)行`mysql --help`會發(fā)現(xiàn)有如下輸出:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
The following groups are read: mysql client
由于/etc是系統(tǒng)目錄休弃,建議選擇創(chuàng)建 /usr/local/etc/my.cnf 或者 ~/.my.cnf 文件吞歼;
2 從哪拷貝一份默認的配置文件 my-default.cnf ?
如果是通過brew安裝的mysql塔猾,一般位于如下的類似目錄中: `/usr/local/Cellar/mysql/5.7.13/support-files/my-default.cnf`
3 mysql5.7 不支持timestamp 默認值為0 怎么處理篙骡?
CREATE TABLE xxxx(
...
`uptime` timestamp NOT NULL default 0,
...
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
上述sql在5.7版本中執(zhí)行會報錯,Invalid default value for 'uptime'
丈甸;需要手動更改mysql的配置文件糯俗。打開my.cnf文件,添加如下配置睦擂;
sql_mode=ONLY_FULL_GROUP_BY,NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES
參考鏈接
https://my.oschina.net/u/192792/blog/652627
https://my.oschina.net/phpyer/blog/133042
http://stackoverflow.com/questions/7973927/for-homebrew-mysql-installs-wheres-my-cnf