sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_

Mysql8.0 only_full_group_by and above as well as other causes of error in detail about sql_mode Solutions

0.279 1,606 words read 9,038

Today we are speaking about the issue at mysql8 only_full_group_by, I believe that everyone in the group by using the function will suddenly jump out of a error message:

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

In the above mysql8.0 version, for this group by aggregate operations, if the column in the select, does not appear in the group by, then this SQL is not legitimate, because the column is not in the group by clause, so for this mode of setting up a database, when using group by, we must use MAX (), SUM (), ANT_VALUE () this aggregate function, to complete the polymerization GROUP bY operation, so having said that, how to turn off it?

After we have some Baidu, the result obtained is about only_full_group_by, but follow the tutorial said, just modify the my.cnf,

Adding follows my.cnf

[mysqld]

sql_mode='NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES'

Configuration file by adding the appropriate parameter [hereinafter will be referred] to restart the time, it is still far from satisfactory, even people who did not give tutorials to hands-on test, to put out, but also bring new mysql error, or completely start being given, today I come to you one by one with detailed description of these parameters, and solutions.

sql_mode variable, it is easily overlooked, the default value is a null value, in this arrangement is to allow some illegal operations, such as allowing some invalid data is inserted. This value must be set to strict mode in a production environment, the development, test environment database must be set so that the development and testing phases can find the problem.

sql_mode common values ​​are as follows: 

ONLY_FULL_GROUP_BY: For GROUP BY aggregate operations, if a column in the SELECT, does not appear in a GROUP BY, then the SQL is not legitimate, because the column is not in the GROUP BY clause.

NO_AUTO_VALUE_ON_ZERO: The value is inserted from the impact of the growth column. In the default setting, the insert 0 or NULL on behalf of a self-generated growth value. If you want to insert a value of 0, and that column is self-growth, this option comes in handy.

STRICT_TRANS_TABLES: In this mode, if a value can not be inserted into a transaction table, interrupting the current operation, which is not limited to non-transactional tables

NO_ZERO_IN_DATE: in strict mode, the date and month of zero is not allowed

NO_ZERO_DATE: Set the value, mysql database does not allow zero-insertion date, insert zero dates will throw an error instead of a warning.

ERROR_FOR_DIVISION_BY_ZERO: INSERT or UPDATE in the process, if the data is zero, an error rather than a warning. If this mode is not given, then return NULL when data MySQL zero

GRANT prohibit users create a blank password: NO_AUTO_CREATE_USER

NO_ENGINE_SUBSTITUTION: If you need a storage engine is disabled or not compiled, then throw an error. When this value is not set, the default storage engine replacement, and throws an exception

PIPES_AS_CONCAT: the "||" operator not regarded as connection strings or operator, and that the Oracle database is the same, and also blending functions similar string Concat

ANSI_QUOTES: ANSI_QUOTES then enabled, can not be used to refer to a string double quotation marks, because it is interpreted as an identifier

Description introduction is over, but still being given at 8.0 in such a setting, for the following reasons:

ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'

8.0 above has been canceled NO_AUTO_CREATE_USER keyword, delete the keyword to sql statement

Finally, / etc / my.cnf modified configuration file: sql_mode = 'STRICT_TRANS_TABLES, NO_ZERO_IN_DATE, NO_ZERO_DATE, ERROR_FOR_DIVISION_BY_ZERO, NO_ENGINE_SUBSTITUTION' 

Mysql restart the service, you're done! ~

Here, I give the other two solutions:

The second approach without modifying the configuration file, modify the use navicat

Enter the command line interface

Enter: SELECT @@ GLOBAL.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

Then we modify sql_mode

set GLOBAL sql_mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION ';

Run your sql, group by can be used, but this method is not a cure, after the restart mysql, still can not use the group by So, the first method is the most effective.

A third approach without modifying the configuration file, modify the use navicat

Enter the command line interface

Enter: SELECT @@ sql_mode; Note: This way, the default session, is complete: SELECT @@ SESSION.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

Then we modify sql_mode

输入: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 ';

And then run your sql:

***** ***** wrong or reported only_full_group_by

##############Solution###################

Before you set sql_mode statement query

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 ';

Later the New Query (includes group by) statements do not set sql_mode together until you close this connection so far

Then you run your sql is not able to run it

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';

SELECT @@GLOBAL.sql_mode;

Explanation of the way 3:

1. In fact, when talking about the third method mentioned SELECT @@ sql_mode; in fact, here the default session, is complete: SELECT @@ SESSION.sql_mode;

2.SESSION current session is meant ----> This would explain the connection until you close up

3. Why the command line set sql_mode, and then create a new query or useless it?

4. In fact, you just type SELECT @@ sql_mode in the new query; you will find that you set on the command line and do not take effect

5. Therefore, we can only again in this connection (session) of the New Query re-set sql_mode, after the connection (this session) is no longer needed

6. This section explains the language "set before the statement your query sql_mode" This sentence

2 description of the way the two methods of approach 3

Contents 1. Both set sql_mode methods, as will restart mysql on my linux deployment while I return to the specified configuration file sql-mode option in my.cnf set up inside

2. Compare this sentence about

3. means: after the restart mysql on linux, you are no longer valid set on navicat, but based on your specified configuration file settings, this file is set in my.cnf


Note: I will now my.cnf listed for your reference

3 thumbs up
"Small gifts around and Jane book to my attention."
Appreciate the support no one appreciates support what
Total assets 18 (approximately 153 million) were written word 2.8W obtained Like 33 of 13 fans
attention
Original articles published 0 · won praise 0 · Views 21

Guess you like

Origin blog.csdn.net/qq_45060236/article/details/105357666