报错
ERROR 1055 (42000): Expression #7 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'postscan.verifyDelayLog.auditor' which is not functionally dependent on columns in GROUP BY clause; this is incompatible withsql_mode=only_full_group_by
原因
在mysql
的高版本(5.7以上的版本)中,诸如 group by
的聚合操作,如果select
时查询的列,没有包含在group by
中,那么这个SQL
会被认为是非法操作。因为列不在group by
的从句中,所以对于设置了这个mode
的数据库,在使用group by
的时候,就要用MAX(),SUM(),ANT_VALUE()
的这种聚合函数,才能完成GROUP BY
的聚合操作。
解决方案
- 临时
- 永久:修改
my.cfn
文件,添加sql_mode配置,并重新启动Mysql。
修改my.cnf文件
在[mysqld]
下增加配置
sql_mode="STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_ENGINE_SUBSTITUTION"
# aba
完整的my.cfn
配置如下:
[mysql]
# 设置mysql客户端默认字符集
default-character-set=utf8mb4
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
port = 3306
server-id = 3306
user = mysql
socket = /tmp/mysql.sock
# 设置mysql的安装目录
basedir = /usr/local/mysql
# 设置mysql数据库的数据的存放目录
datadir = /data/mysql8_data/mysql
log-bin = /data/mysql8_data/mysql/mysql-bin
innodb_data_home_dir =/data/mysql8_data/mysql
innodb_log_group_home_dir =/data/mysql8_data/mysql
#设置mysql数据库的日志及进程数据的存放目录
log-error =/data/mysql8_data/mysql/mysql.log
pid-file =/data/mysql8_data/mysql/mysql.pid
# 服务端使用的字符集默认为8比特编码
character-set-server=utf8mb4
lower_case_table_names=1
autocommit =1
##################以上要修改的########################
skip-external-locking
key_buffer_size = 256M
max_allowed_packet = 1M
table_open_cache = 1024
sort_buffer_size = 4M
net_buffer_length = 8K
read_buffer_size = 4M
read_rnd_buffer_size = 512K
myisam_sort_buffer_size = 64M
thread_cache_size = 128
#query_cache_size = 128M
tmp_table_size = 128M
explicit_defaults_for_timestamp = true
max_connections = 500
max_connect_errors = 100
open_files_limit = 65535
binlog_format=mixed
binlog_expire_logs_seconds =864000
# 创建新表时将使用的默认存储引擎
default_storage_engine = InnoDB
innodb_data_file_path = ibdata1:10M:autoextend
innodb_buffer_pool_size = 1024M
innodb_log_file_size = 256M
innodb_log_buffer_size = 8M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
transaction-isolation=READ-COMMITTED
# 修改model
sql_mode="STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,TRADITIONAL,NO_ENGINE_SUBSTITUTION"
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 256M
sort_buffer_size = 4M
read_buffer = 2M
write_buffer = 2M
[mysqlhotcopy]
interactive-timeout