Home >Database >Mysql Tutorial >How to Permanently Set Global SQL_MODE in MySQL?
When working with MySQL, one often encounters the need to modify the SQL_MODE setting. This mode governs a range of SQL behavior and parser configurations, affecting factors such as data validation, transaction handling, and more.
The syntax for setting multiple modes in SQL_MODE using the SET command is correct:
SET GLOBAL SQL_MODE='NO_BACKSLASH_ESCAPES','STRICT_TRANS_TABLE','NO_AUTO_CREATE_USER','NO_ENGINE_SUBSTITUTION'
When faced with a scenario like updating the database with UNC values using different users, setting a global mode for NO_BACKSLASH_ESCAPES makes sense because it ensures that all users are affected, regardless of their session settings.
Unfortunately, direct modification of global settings using SET is not persistent and resets after MySQL restart. To make changes permanent, set the mode in the configuration file(/etc/mysql/my.cnf):
[mysqld] sql_mode = NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
For newer MySQL versions (e.g., 5.7.8 ), use the following syntax:
[mysqld] sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
For system-wide, persistent SQL_MODE settings that affect all users, setting a global mode is the preferred approach. Permanent changes should be made in the configuration file, ensuring that the desired SQL behavior is consistent across sessions.
The above is the detailed content of How to Permanently Set Global SQL_MODE in MySQL?. For more information, please follow other related articles on the PHP Chinese website!