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

相关推荐

  • log4j 0day漏洞情况分析及说明

    一、背景简介 2022年7月30日起,各大威胁情报社区及安全圈内开始盛传log4j存在0day漏洞,由于log4j在去年12月爆出严重的jndi注入漏洞,可通过在特定点插入恶意的jndi payload达到执行任意代码进而控制主机的目的。 log4j2(一般简称log4j)是Apache基金会开发维护的开源java日志组件,在以Java开发的系统中大量被直接…

    2022年8月3日
    78300
  • nacos 开启密码验证

    默认情况下获取 Nacos 中的配置是不需要权限认证的, 这个估计是由其使用场景决定的(绝大多数都是仅内网可访问).今天调查了下如何在获取配置时增加权限验证以提高其安全性. 1. 启用 Nacos 的权限认证 只要 nacos.core.auth.enabled 设置为 true 就行了. ### If turn on auth system: nacos….

    2022年6月28日
    893410
  • 关于Apache log4j存在远程代码执行漏洞的预警

    12月9日晚,互联网上公开了Apache log4j2的一个严重级别的远程代码执行漏洞。由于Apache log4j2某些功能存在递归解析功能,攻击者可直接构造恶意请求触发远程代码执行漏洞,而无需特殊配置。Apache Struts2、Apache Solr、Apache Druid、Apache Flink等均受此漏洞影响。鉴于该框架应用范围极广,且漏洞利…

    2022年8月3日
    843120
  • ChatGPT对话:结婚视频制作是用了什么技术呢,有很多平台上给用户提供个视频模板,然后把自己图片上传上去就可以自动化生成一个视频,背后的技术是什么呢?

    问:结婚视频制作是用了什么技术呢,有很多平台上给用户提供个视频模板,然后把自己图片上传上去就可以自动化生成一个视频,背后的技术是什么呢?详细说明下 答:结婚视频制作通常涉及到多个技术领域,包括视频编辑、图像处理、人工智能等。在现代科技的支持下,许多平台都能够通过提供视频模板、自动化生成等方式来帮助用户制作结婚视频。 具体来说,结婚视频制作平台的背后技术主要包…

    2023年2月17日
    11.2K11300
  • 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日
    977380

回复 100 USDT

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

评论列表(15条)

  • 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?

  • 100 USDT
    100 USDT 2025年2月5日 02:20

    Can you be more specific about the content of your article? After reading it, I still have some doubts. Hope you can help me.

  • Michaelambub
    Michaelambub 2025年2月22日 11:23

    Undeniably consider that which you stated. Your favorite justification seemed to be on the internet the easiest thing to take into accout of. I say to you, I certainly get irked even as folks consider issues that they plainly do not realize about. You controlled to hit the nail upon the top as smartly as defined out the whole thing with no need side-effects, other people can take a signal. Will probably be back to get more. Thank you

    [url=https://sips.ae/unleash-the-thrill-at-dafabet-betting-official-website/]sips.ae[/url]

  • Michaelambub
    Michaelambub 2025年2月25日 04:14

    I am regular reader, how are you everybody? This post posted at this website is genuinely fastidious.

    iptv-ottpremium.store

  • Click
    Click 2025年2月28日 07:03

    When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get three emails with the same comment. Is there any way you can remove people from that service? Thanks a lot!

  • Click
    Click 2025年3月3日 04:38

    I think the admin of this website is in fact working hard in favor of his website, since here every stuff is quality based material.

  • Click
    Click 2025年3月8日 06:46

    hello!,I like your writing so much! share we be in contact extra approximately your article on AOL? I require a specialist in this space to resolve my problem. May be that is you! Looking ahead to look you.