MySQL exception error 1055 (42000) description

Source: Internet
Author: User

The specific exception information is as follows:

ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP by clause and contains nonaggregated column ' Aaa.test.age ' Which is not functionally dependent on columns in GROUP by clause; This was incompatible with sql_mode=only_full_group_by


Execute such an SQL statement to reproduce the exception select age, name from test group by name

mysql5.1, no exception reported

mysql5.5, no exception reported

mysql5.6, no exception reported

mysql5.7.22, reported abnormal ( specific from 5.7 which version has not been determined, online someone said 5.7.5)


MySQL has adjusted the default parameter Sql_mode value from a version of 5.7 to:

mysql> show variables like  ' sql_mode '; +---------------+-------------------------------- -----------------------------------------------------------------------------------------------------------+|  variable_name | value                                                                                                                                            |+---------------+-------------------------------------- -----------------------------------------------------------------------------------------------------+|  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 |+---------------+------- --------------------------------------------------------------------------------------------------------------- ---------------------+1 row in set  (0.00 sec) mysql>

Where only_full_group_by is the effect of the above SQL statement is not reported exception


Workaround:

1, rewrite the SQL statement, after all, the above writing is not a standard SQL statement

2. Log in to MySQL server and execute the following commands, both at global and session level.

mysql> 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 ';mysql> set session 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, combined with the 2nd method, in the My.cnf file, specify the value of Sql_mode:

[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


Note: The combination of 2 and 3 does not restart the server and is still valid even if the restart configuration is in effect.

MySQL exception error 1055 (42000) description

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.