MySQL / MariaDB: Disable strict mode | Upgrading to MariaDB 10.2

We recently needed to upgrade a server from MySQL 5.7 to MariaDB 10.3 and one of the key steps in doing so is to disable strict mode after the upgrade. By default, MariaDB enables strict mode from version 10.2 and onwards.

Having this enabled can cause various issues, a few below:

  • Can break your application
  • SQL insert queries that previous worked, with missing or invalid data, will stop and  start throwing errors

An example of this is the following:

We’re trying to enter data without the date, leaving it blank

With strict mode enabled it’ll throw an error like the following:

Conventionally, and with strict mode disabled, this would let the query go through warning of missing data but not stopping the query from executing. Something like this:

A better and obvious approach could be alter the application to allow for null entries, automatically insert real dates etc. But that is not the scope of this article, if this is a shared hosting then it is going to be virtually impossible to go around to your clients asking them to make the necessary changes.

To disable strict mode, locate your my.cnf file. This is either going to be in /etc/my.cnf or /etc/my.cnf.d/server.cnf depending on your OS and installation type. Edit the my.cnf file and under [mysqlnd] add the following line:

Save and restart MariaDB

That’s it, you’re done.