mysql allow invalid dates on select mysql allow invalid dates on select sql sql

mysql allow invalid dates on select


This is what I do to ignore invalid dates:

SET SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';


  • Log into mysql in the command line mysql -u root -p
  • Enter your password
  • View the current sql-modes using SELECT @@GLOBAL.sql_mode;
  • Copy the current modes (add or delete modes as needed) and paste in next step.
  • Set the sql-modes using SET 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 both NO_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