MySQL 版本:
$ brew info mysql
mysql: stable 5.7.21 (bottled), devel 8.0.4-rc
Open source relational database management system
https://dev.mysql.com/doc/refman/5.7/en/
Conflicts with:
mariadb (because mysql, mariadb, and percona install the same binaries.)
mariadb-connector-c (because both install plugins)
mysql-cluster (because mysql, mariadb, and percona install the same binaries.)
mysql-connector-c (because both install MySQL client libraries)
percona-server (because mysql, mariadb, and percona install the same binaries.)
/usr/local/Cellar/mysql/5.7.21 (323 files, 235.0MB) *
Poured from bottle on 2018-03-13 at 16:09:50
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/mysql.rb
问题
使用 sql 查询时 mysql 报如下错误,
完整报错如下:
err:Error 1055: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'projectkdb.detail_local.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by ctx:context.Ba ckground.WithValue(1, “505b934")
经查,是由于默认的 MySQL 配置中 sql_mode
配置了 only_full_group
,需要 GROUP BY
中包含所有 在 SELECT 中出现的字段。因此需要在 MySQL 的配置中去掉这个配置。
使用 SQL 语句可以查询这个配置:
select @@sql_mode;
解决方法
在 配置文件(my.cnf)中 修改 sql_mode
的配置为:
$ vim /usr/local/etc/my.cnf
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
具体的配置文件的位置请参照: