zoukankan      html  css  js  c++  java
  • mysql group by 过滤字段 只能在SELECT 后面出现,不能写其他字段 报错解决 关键字 sql_mode=only_full_group_by

    1:报错  关键字 sql_mode=only_full_group_by
    mysql> select uuid,ip,count(*) from dbname_report.t_client_ips group by uuid limit 1;
    ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dbname_report.t_client_ips.ip' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

    2:查看模式
    mysql> select @@global.sql_mode
    -> ;
    +------------------------------------------------------------------------------------------------------------------------+
    | @@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 |
    +------------------------------------------------------------------------------------------------------------------------+
    1 row in set (0.01 sec)

    3:设置模式

    mysql> set @@global.sql_mode = 'STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'
    -> ;
    Query OK, 0 rows affected, 2 warnings (0.00 sec)

    mysql> select uuid,ip,count(*) from dbname_report.t_client_ips group by uuid limit 1;
    ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'dbname_report.t_client_ips.ip' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
    mysql> select @@global.sql_mode;

    4:查看
    +--------------------------------------------+
    | @@global.sql_mode |
    +--------------------------------------------+
    | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
    +--------------------------------------------+
    1 row in set (0.00 sec)

    5:执行还是报错

    6:修改数据库配置文件

    cat /etc/my.cnf

    [mysqld]

    sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

    7:重启数据库,可以解决

  • 相关阅读:
    java代码连接数据库
    phpcms v9 读取地区联动菜单缓存文件
    PHPCMS V9二次开发便捷自定义后台入口文件夹
    phpcms v9中模板标签使用及联动菜单
    Phpcms v9系统类库与函数库调用方法
    phpcms v9 二次开发
    phpcms v9开源开发框架基础mvc解读
    phpcms插件开发初步规范
    phpcms v9二次开发之模型类的应用(1)
    phpcms v9二次开发之模型类的应用(2)
  • 原文地址:https://www.cnblogs.com/liuyoushui/p/8580553.html
Copyright © 2011-2022 走看看