Home >Database >Mysql Tutorial >How to Set and Persist Global SQL Modes in MySQL?
The command you provided is incorrect for setting multiple SQL modes globally. The correct syntax is:
SET GLOBAL sql_mode='NO_BACKSLASH_ESCAPES,STRICT_TRANS_TABLE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
Session modes: Affect only the current connection and are reset upon connection termination. Advantages include:
Global modes: Affect all connections to the database. Advantages include:
The preferred mode depends on the specific requirements and usage patterns. If the same SQL mode is desired for all users, setting a global mode is recommended. Otherwise, session modes can provide flexibility.
Note that setting SQL modes with SET GLOBAL will not persist after a MySQL restart. To make changes permanent, you should update the MySQL configuration file (e.g., my.cnf) as follows:
[mysqld] sql_mode = 'NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES'
For MySQL versions 5.7.8 and above, use the following syntax:
[mysqld] sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
Make sure to consult the MySQL documentation for your specific version for the available SQL mode options.
The above is the detailed content of How to Set and Persist Global SQL Modes in MySQL?. For more information, please follow other related articles on the PHP Chinese website!