Home > Database > Mysql Tutorial > MySQL服务器的SQL模式_MySQL

MySQL服务器的SQL模式_MySQL

WBOY
Release: 2016-06-01 13:37:20
Original
935 people have browsed it

bitsCN.com


sql_mode的系统变量可以调控MySQL的SQL模式

任何一个客户端可以在不影响其它客户端的情况下改变MySQL服务器对自己的反应

MySQL服务器的SQL模式_MySQL

 

如果想在MySQL启动时设置SQL模式,可以在mysql配置文件中添加sql_mode选项

sql-mode=”TRADITIONAL”

如果在运行过程中修改SQL模式,则可以使用如下命令

setsql_mode="TRADITIONAL";

Client1

 

mysql> show variables like "sql_mode";

 

+---------------+-------+

 

| Variable_name | Value |

 

+---------------+-------+

 

| sql_mode||

 

+---------------+-------+

 

1 row in set (0.00 sec)

 

mysql> set sql_mode="TRADITIONAL";

 

Query OK, 0 rows affected(0.23 sec)

 

mysql> show variables like "sql_mode";

 

+---------------+---------------------------------------------------------------------------------------------------------

 

|Variable_name |Value |

 

+---------------+-----------------------------------------------------------------------------------------------------------

 

|sql_mode|STRICT_TRANS_TABLES,STRICT_ALL_TABLES,NO_ZERO_IN_DATE,NO_ZERO
_DATE,ERROR_FOR_pISION_BY_ZERO,TRADITIONAL,NO_AUTO_CREATE_USER,NO_
ENGINE_SUBSTITUTION|

 

+---------------+------------------------------------------------------------------------------------------------------------

 

1 rowin set (0.00 sec)

 

mysql>

Client2

Client1已经修改了SQL模式,但是Client2的SQL模式没有改变,这就说明客户端之间的模式修改
是互相不影响的

 

mysql> show variables like "sql_mode";

 

+---------------+-------+

 

| Variable_name | Value |

 

+---------------+-------+

 

| sql_mode||

 

+---------------+-------+

 

1 row in set (0.00 sec)

 

mysql>

设置全局变量(设置全局变量设置,需要加上GLOBAL关键字,需要SUPER权限)

mysql> set globalsql_mode="traditional";

Query OK, 0 rows affected(0.02 sec)
 

select@@session.sql_mode --》查看当前会话sql模式

select@@GLOBAL.sql_mode --》查看系统会话sql模式

设置全局变量后,新连接的客户端默认的就是全局的SQL模式
 

bitsCN.com
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template