mysql query error caused by only_full_group_by

tags: Pits encountered  mysql

1. The cloud cause of the problem

After MySQL 5.7.5, ONLY_FULL_GROUP_BY is turned on by default, so some of the previous SQL cannot be executed normally. In fact, it is caused by our SQL irregularities, because after the group by, some data returned is uncertain, so it will This error occurred.

2. The error is as follows

{"code":1,"data":{},"msg":"\n### Error querying database.  Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'a.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by\n### The error may exist in team/gk18software1dev/pcrsys/mapper/StudentMapper.java (best guess)\n### The error may involve team.gk18software1dev.pcrsys.mapper.StudentMapper.getListOnSelectByPcId-Inline\n### The error occurred while setting parameters\n### SQL: SELECT * from ( SELECT * from ( select student_choose_project.id,student_choose_project.stu_id, student_choose_project.pc_id,student_choose_project.p_id,student_choose_project.`status`, student.class_name,student.`name`,student.stu_number,student.telephone, student.station_name,student.wechat_num,student.email,student.remark from student_choose_project LEFT JOIN student on student_choose_project.stu_id=student.stu_id O

3. Solve

Turn off ONLY_FULL_GROUP_BY
Method 1:

  • View
select @@global.sql_mode;
  • Set up
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';
  • Refresh
flush privileges;

Method Two:
Linux solution steps:

①, login into MySQL, linux login:mysql -u username -p , And then enter the password, enter SQL:show variables like '%sql_mode';

②. Edit the my.cnf file, the file address is generally:/etc/my.cnf/etc/mysql/my.cnf,turn upsql-modePosition, removeONLY_FULL_GROUP_BY,thenRestart MySQL; Some my.cnf does not have sql-mode, you need to add:

sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,Note that if you want to add it under [mysqld], I just added it to other places, and it won't take effect after restarting.
  
③, restart the MySQL service after the modification is successful,service mysql restartAfter restarting, log in to mysql and enter SQL:show variables like '%sql_mode'; If there is no ONLY_FULL_GROUP_BY, it meanssuccessUp.

Intelligent Recommendation

Mysql error sql_mode=only_full_group_by

Remember once, when you migrate the service, connect to the new database, the database is also the backup of the previous, found an error:   I started thinking that it was wrong when I imported i...

mysql ONLY_FULL_GROUP_BY error

mysql ONLY_FULL_GROUP_BY error Error message: Solution: 1. error occurs again after the current environment modified configuration, service restart 2 Modify the start mysql my.ini configuration file t...

MySql group by error, only_full_group_by? ? ?

The following is the error message: The reason is: The default mode of the MySQL version 5.7 and later database is set to only_full_group_by mode, and when there are some duplicate rows in the execute...

MySql error only_full_group_by solution

Some time ago, when I deployed a program in a new environment, I encountered the MySql error only_full_group_by. I have encountered the same problem before. At that time, I did not summarize the exper...

MySQL sql_mode=only_full_group_by error

Now that you know the problem, you can modify this configuration, find the MySQL configuration file, and query the sql_mode field in the /etc/my.cnf file on the linux system. I did not find this keywo...

More Recommendation

Solve mysql only_full_group_by error

Solve mysql only_full_group_by error Reference article: 1. Problem We sometimes encounter the following problems when performing a group of SQL statements: ERROR 1055 (42000): Expression #1 of SELECT ...

mysql error this is incompatible with sql_mode = only_full_group_by

mysql5.7 + version is turned on by defaultonly_full_group_byMode,When you turn on this mode, the column must query conditions are grouped. The original group by statement will be reported this error. ...

MySQL sql_mode=only_full_group_by error (solved)

On database 5.7, only_full_group_by mode will be enabled by default, but after enabling this mode, the original group by statement will report an error. Cause Analysis: For group by aggregation operat...

The error of mysql sql_mode=only_full_group_by in mybatis.

I wrote an sql when using mybits in the project: It was correct when tested on a machine, but it was wrong when it was put on the server: This matter caused an error because some versions of mysql5.7 ...

mysql error: this is incompatible with sql_mode=only_full_group_by

Solution: modify the mysql configuration file The local server can modify this Add under [mysqld] Then restart service mysql restart  ...

Copyright  DMCA © 2018-2026 - All Rights Reserved - www.programmersought.com  User Notice

Top