mysql查询报错: ORDER BY clause is not in GROUP BY..this is incompatible with sql_mode=only_full_group_by
前些天發現了一個巨牛的人工智能學習網站,通俗易懂,風趣幽默,忍不住分享一下給大家。點擊跳轉到教程。
我的情況 :
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?
?
?
?
?
總結
以上是生活随笔為你收集整理的mysql查询报错: ORDER BY clause is not in GROUP BY..this is incompatible with sql_mode=only_full_group_by的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 几个.net开发中常用的工具下载
- 下一篇: EveryEeek English(9.