如何在MySQL中启用严格的sql_mode?
如何在MySQL中启用严格的sql_mode
?
How can I enable strict sql_mode
in MySQL?
我想从SQL中获取数据并在strict
模式下对其进行处理.
I want to fetch data from SQL and process the same in strict
mode.
我当前的sql_mode
是:
mysql> SELECT @@sql_mode;
+------------------------+
| @@sql_mode |
+------------------------+
| NO_ENGINE_SUBSTITUTION |
+------------------------+
您基本上可以通过两种方法来执行此操作,即使用SQL命令或更改配置文件.如果使用SQL命令进行设置-服务器重新启动后,它会变回原来的状态.
You basically have two ways of doing it, using SQL command or changing configuration file. If you set it using SQL command - it will change back after the server is restarted.
在SQL中执行
SET GLOBAL sql_mode='STRICT_TRANS_TABLES';
在配置文件中执行此操作
Doing it in config file:
[mysqld]
sql_mode="STRICT_TRANS_TABLES"
[mysqld]
sql_mode="STRICT_TRANS_TABLES"
文件位置因您的操作系统而异,更多有关在此处找到文件的位置: https://dev.mysql.com/doc/refman/5.7/en/option-files.html
File location varies depending on your operating system, more on where to find it here: https://dev.mysql.com/doc/refman/5.7/en/option-files.html
重要的是,您可以指定多种模式:
Important to note, that you can have multiple modes specified:
sql_mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
这在使用SQL语句时尤其重要,因为它可以覆盖整个模式字符串.
this is especially important when using SQL statement, since it could override your whole mode string.
有关SQL模式的更多信息,请参见: https://dev .mysql.com/doc/refman/5.7/en/sql-mode.html
More stuff about SQL modes here: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html