MySQL5.7版本sql_mode=only_full_group_by问题解决办法

1055 – Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘csc_risk.a.DefaultDate’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by, Time: 0.035000s 

于是把部分数据迁移到本地进行测试,  发现sql语句可以执行

查看本地数据库版本

SELECT VERSION()

 查询线上数据库版本发现确实是5.7版本

5.7.24

原因分析:MySQL5.7版本默认设置了 mysql sql_mode = only_full_group_by 属性,导致报错。

知道原因就好办, 查询怎么解决 

下载安装的是最新版的mysql5.7.x版本,默认是开启了 only_full_group_by 模式的,但开启这个模式后,原先的 group by 语句就报错,然后又把它移除了。

一旦开启 only_full_group_by ,感觉,group by 将变成和 distinct 一样,只能获取受到其影响的字段信息,无法和其他未受其影响的字段共存,这样,group by 的功能将变得十分狭窄了

only_full_group_by 模式开启比较好。因为在 mysql 中有一个函数: any_value(field) 允许,非分组字段的出现(和关闭 only_full_group_by 模式有相同效果)。

1、查看sql_mode

SELECT @@sql_mode;

查询出来的值为:

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

2、去掉ONLY_FULL_GROUP_BY 重新设置值

SET @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

3、上面是改变了全局sql_mode 对于新建的数据库有效, 对于已存在的数据库,则需要在对应的数据下执行:

SET sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

以上方式临时解决没有问题的,数据库重启就需要重新设置

修改MySQL配置文件

Linux下my.cnf或Windows下My.ini

注意在[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

发布者:小站,转转请注明出处:http://blog.gzcity.top/4651.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022年6月28日 09:38
下一篇 2022年7月5日 10:45

相关推荐

  • Linux命令汇总 | vim | shell | 进阶【2022版】

    Linux大全 一、Linux上下五千年 1.1 历史长河 Linux,全称GNU/Linux,是一种免费使用和自由传播的类UNIX操作系统,其内核由林纳斯·本纳第克特·托瓦兹于1991年10月5日首次发布。 它主要受到Minix和Unix思想的启发,是一个基于POSIX的多用户、多任务、支持多线程和多CPU的操作系统。它能运行主要的Unix工具软件、应用程…

    2022年6月24日
    27100
  • Android版本 (1.0~12.0) 与API Level (SDK版本1~32) 对应表

    什么是 API 级别? API 级别是一个对 Android 平台版本提供的框架 API 修订版进行唯一标识的整数值。 Android 平台提供了一种框架 API,应用可利用它与底层 Android 系统进行交互。 该框架 API 由以下部分组成: 一组核心软件包和类 一组用于声明清单文件的 XML 元素和属性 一组用于声明和访问资源的 XML 元素和属性 …

    Java 2023年6月1日
    17.5K24940
  • Java多线程方式快速解析大量文本内容得到pdf链接转换为文本-学习笔记

    Java多线程方式快速解析大量文本内容得到pdf链接转换为文本-学习笔记 解析流程: 1、一个目录里面包含大量多种格式文件;2、从目录中提取txt为后缀的文件路径List;3、根据服务器性能设定多线程处理文本数量;4、txt文本中获取所有的链接;5、通过正则提取后缀为.pdf链接;6、下载pdf文件到本地;7、使用开源工具把pdf转换为txt内容;获取链接正…

    2022年5月2日
    7.3K9770
  • 使用FFmpeg实现抠图合并功能(chroma key)

    自己以前实现抠图算法好久了,没想到ffmpeg里面早有这个功能了在很多视频中可以看到图像是合成的,例如有些神剧里面某大侠跳下万丈深渊的场景,某人在三昧真火中被烧的场景,还有些游戏主播,体育主播在效果图如下: 在最新版本的ffmpeg中,已经增加了chroma key功能的filter,只需要一条命令即可搞定 ./ffmpeg –i ~/fuck….

    2022年7月11日
    4.3K10780
  • linux启动php-cgi,linux下php-fpm启动参数及重要配置

    php-fpm我们并不陌生了,下面来介绍一篇php-fpm 启动参数及重要配置的文章,如果各位对于php-fpm 启动参数及重要配置不了解可以进来看看。 约定几个目录 /usr/local/php/sbin/php-fpm /usr/local/php/etc/php-fpm.conf /usr/local/php/etc/php.ini I. php-fp…

    学习笔记 2022年9月25日
    388370

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

评论列表(9条)

  • binance
    binance 2024年8月17日 12:22

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?

  • أنابيب النحاس
    أنابيب النحاس 2024年9月25日 17:14

    Galvanized Steel Pipes in Iraq ElitePipe Factory is renowned as one of the best and most reliable manufacturers of galvanized steel pipes in Iraq. Our galvanized steel pipes are produced with precision and high-quality standards, ensuring durability and resistance to corrosion. These pipes are ideal for a variety of applications, including water supply, construction, and industrial uses. With our state-of-the-art facilities and commitment to excellence, ElitePipe Factory has established a reputation for delivering top-notch products that meet the needs of our clients effectively. Discover more about our galvanized steel pipes by visiting our website at ElitePipe Iraq.

  • sex porn mom
    sex porn mom 2024年10月2日 11:19

    He reaches for and cups the wiggling low hangers of his teenage son. [url=https://arturzasada.pl/]polskie porno[/url] “I don’t wanna jack-off, dad.” He says flabbergasted to his dad as he turns off the tap to the hot and chilly water in the shower.

  • gay sex porn
    gay sex porn 2024年10月3日 05:41

    “Yes! Yes! I know you understand.” His father proudly exclaims. “You guys jerk off together, these days?” His dad asks, “Back when I was in high school me and several of my friends would jerk-off in our trucks in the parking lot. We were so horny we could barely sit in our seats. You ever do that Garrett?”

  • porno dla dzieci
    porno dla dzieci 2024年10月5日 19:40

    Exactly a week after, daddy texted me with a different tone saying, “ get your ass ready tonight cause daddy is coming to your place tonight.” He was usually really sweet and nice, I was shot when I got the message. But automatically I said, “ yes daddy!” I guess I am a slutty whore for him right at the beginning as I knew my place where is always going to be inferior. He reaches for and cups the wiggling low hangers of his teenage son.

  • gay sex porn
    gay sex porn 2024年10月7日 05:41

    “What are ya now, by the way?” I used my teeth to strip off daddy’s black sheer socks. I placed them in my mouth and washed them with my saliva. I swallowed every single sweat and stink from these socks. It takes so well. I rolled them into a ball and stuck them into my jockstrap where my small dick and balls were.

  • free porn sex
    free porn sex 2024年10月11日 09:27

    His father strokes his own cock in the shower, the dew from his cock mixes with the drops condensing on the glass.

  • dzieciece porno
    dzieciece porno 2024年10月13日 21:10

    Exactly a week after, daddy texted me with a different tone saying, “ get your ass ready tonight cause daddy is coming to your place tonight.” He was usually really sweet and nice, I was shot when I got the message. But automatically I said, “ yes daddy!” I guess I am a slutty whore for him right at the beginning as I knew my place where is always going to be inferior.

  • "oppna binance-konto
    "oppna binance-konto 2024年12月4日 00:47

    Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?