Disable Mysql Strict Mode in CentOS/WHM/cPanel

To disable mysql strict mode in mysql (especially version 5.6) on a cPanel server, you would want to first ssh in to the server then before you do anything else it would be good to make a backup of the mysql configrations:

cp -rp /etc/my.cnf /etc/my.cnf.backup
cp -rp /usr/my.cnf /usr/my.cnf.backup

Then edit the main mysql configuration file like so:

vim /etc/my.cnf

Then there may or may not be content in this file already, if there is look for the section that starts with:

[mysqld]

If that line is not there at all, just add it near the top of the file. Then if there is a line that starts with “sql_mode”, edit it so it matches this line:

sql_mode=”NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”

then save the file by pressing the Escape key then typing:

:wq

Then press the Enter to Save the file. If you have mysql 5.6 make sure to make a similar change in the /usr/my.cnf file as well:

vim /usr/my.cnf

by default it usually shows:

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

So change that to:

sql_mode=”NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”

Save the file again by pressing the escape key and typing “:wq” then Enter again. Now restart mysql using:

service mysql restart

Hopefully if everything went well you don’t get any error messages and mysql starts successfully. If not you can try moving those backup files originally created back into place and restarting it again.

Finally to test it run this command:

[root@host ~]# mysql -e 'select @@GLOBAL.sql_mode;'
+----------------------------------------------------------------------------------------------------+
| @@GLOBAL.sql_mode |
+----------------------------------------------------------------------------------------------------+
| NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+----------------------------------------------------------------------------------------------------+

If your output there looks similar, then mysql strict mode should be disabled now. Go ahead and test it out and see if it works!