前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家。点击跳转到教程。
我的情况 :
Mysql 5.7.21 版本运行sql 报错如题,同样的 sql 直接本地运行不报错。
但是当连接的是服务器上的 Mysql 时出现这个报错(即使是运行一个最简单的 select * from 表)。
以下解决方法转自 :https://blog.csdn.net/u014520745/article/details/76056170
在用mysql执行如下查询的时候:
select * from `sys_user_group` group by `GROUP_ID`
- 1
报错信息如下:
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
- 1
错误的原因是我mysql版本是5.7的,使用如下语句查询可知
select @@sql_mode;
- 1
里面默认设置了
sql_mode=only_full_group_by
- 1
only_full_group_by
:使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行,其实这个配置目前个人感觉和distinct差不多的,所以去掉就好
直接修改mysql配置文件(我的系统是Ubuntu16.04的,在/etc/mysql/mysql.conf.d/mysqld.cnf
中并没有sql_mode这个配置,所以直接加上就好,如果是其他系统有得修改就不用添加了)
[mysqld]下
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
- 1
到此mysql配置文件的完整配置如下:
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0[mysqld]
#
# * Basic Settings
#
user = mysql
pid-file = /var/run/mysqld/mysqld.pid
socket = /var/run/mysqld/mysqld.sock
port = 3306
basedir = /usr
datadir = /var/lib/mysql
tmpdir = /tmp
lc-messages-dir = /usr/share/mysql
skip-external-locking
lower_case_table_names=1
character-set-server=utf8
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
#bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer_size = 16M
max_allowed_packet = 16M
thread_stack = 192K