How to change SQL mode 【MySQL】

Tomoharu Tsutsumi
1 min readAug 23, 2020

When you use MySQL, you can change SQL mode. Many settings are included in this, and the contents are written in my.cnf file.

How to find your my.cnf file

mysql --help | grep my.cnf#=>  /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf

Confirm your SQL mode

mysql> SELECT @@GLOBAL.sql_mode;ormysql> SELECT @@SESSION.sql_mode;

The former is a global setting, and latter is a session setting.

List of SQL Modes

It is here => https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#:~:text=The%20default%20SQL%20mode%20in,NO_ZERO_DATE%20%2C%20ERROR_FOR_DIVISION_BY_ZERO%20%2C%20and%20NO_ENGINE_SUBSTITUTION%20

How to change SQL mode

$ service mysql stop$ vi /etc/my.cnfsql-mode = 'sql-mode-name1,sql-mode-name2'ex. sql-mode = 'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE'$ service mysql start

Started LinkedIn as well!

https://www.linkedin.com/in/tomoharu-tsutsumi-56051a126/

--

--

Tomoharu Tsutsumi
Tomoharu Tsutsumi

Written by Tomoharu Tsutsumi

5+ years Full Stack SWE (Ruby, Go, TypeScript, JavaScript) | Former Founding Engineer of AI Startup in Canada

No responses yet