mysql allow invalid dates on select
This one solve my problem. I tested in local MySQL 5.7 ubuntu 18.04.
set global sql_mode="NO_ENGINE_SUBSTITUTION";
Before running this query globally I added a cnf file in /etc/mysql/conf.d directory. The cnf file name is mysql.cnf and codes
[mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Then I restart mysql
sudo service mysql restart
Hope this can help someone.
- Log into mysql in the command line
mysql -u root -p
- Enter your password
- View the current
sql-modes
usingSELECT @@GLOBAL.sql_mode;
- Copy the current modes (add or delete modes as needed) and paste in next step.
- Set the
sql-modes
usingSET GLOBAL sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES';
- This adds
ALLOW_INVALID_DATES
and removes bothNO_ZERO_DATE, NO_ZERO_IN_DATE
- Restart the MySQL server
/etc/init.d/mysql start
SQL Server Modes [Reset configuration file]
Solution Link
- From the command line which mysqld
- Should get something like /usr/sbin/mysqld
which is the location of the binary file
- Sort out the path for the configuration files /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
- Your bash response should look like this: Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
- Look at the files in successive order to see where to make changes (if a file does not exist it is not being referenced).
- Look up your current mode. Open a terminal and log into the mysql database mysql -u database_user -p -e "select @@sql_mode"
- Modify the SQL modes you want to change by adding the following code to the configuration file.
[mysqld]
sql-mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ALLOW_INVALID_DATES"
- Save the configuration file and restart the mysql service
This is what I do to ignore invalid dates:
SET SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';