[Practical] MySQL configuration and importing online data to local problem solving and recording

[ERR] 1292 - Incorrect datetime value: ‘0000-00-0000:00:00‘ for column ‘BIRTH_DATE‘ at row 1

This problem is that the current configuration of mysql does not support the date being empty or '0000-00-0000:00:00'

1. Execute directly in the database

# 修改全局
set @@global.sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
# 修改当前
set @@sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

2. Then refresh and reconnect to the database, and the problem will be solved.

This situation is: the database does not supportDatetime is 0, just change the mode

It can also be configured under mysql.ini (windows)

The execution error is Unknown error 3065.

When distinct and order by are used together in mysql, the field of order by must be in select
mysql 5.7.14

SELECT DISTINCT possible_time FROM possible_etl ORDER BY possible_id ASC;

Because I couldn't find the details of the 3065 error, I did a test:

- 1.SELECT DISTINCT evt_id FROM evt_etl ORDER BY evt_id ASC;

- 2.SELECT DISTINCT evt_tim,evt_id FROM evt_etl ORDER BY evt_id ASC;

- 3.SELECT evt_tim FROM evt_etl ORDER BY evt_id ASC;

1,2,3 These three statements are all executed correctly.

When mysql distinct and order by are used together, the fields of order by must be in select.

I checked the information online and the reasons are summarized as follows:

First of all, the execution order of distinct is higher than order by in mysql.
Second, when distinct is executed, the queried records will be deduplicated and a virtual temporary table will be generated;
Third, when order by is executed, the query will be deduplicated. The virtual temporary table is sorted to generate a new virtual temporary table.
Generally speaking, if the field of order by is not in the select, distinct is executed first when executing the sql statement, and then the virtual temporary table generated does not have the field of order by, so when order by is executed again, Report an error.

 

Solution

Check if this is set in mysql

sql_mode=STRICT_TRANS_TABLES

<p>This error message usually appears in MySQL and it means that the <code>sql_mode</code> parameter is not defined in the MySQL configuration file, or your version of MySQL does not support it. The <code>sql_mode</code> parameter controls the behavior of MySQL when executing queries. Specifically, the <code>NO_ENGINE_SUBSTITUTION</code> parameter disables MySQL from using the default storage engine when it cannot find the specified storage engine, while the <code>STRICT_TRANS_TABLES</code> parameter enables strict transaction mode. , invalid data is not allowed to be inserted. </p>

The STRICT_TRANS_TABLES</code> parameter enables strict transaction mode

In fact, when the sql is not written in a standardized manner, some sql will report an error when mysql is in strict mode.

But when mysql does not set this mode or other modes, these sql are normal

Since this mode is not enabled in production, this setting is also removed here, and the test environment runs normally.

Guess you like

Origin blog.csdn.net/qq_27246521/article/details/134577564