LNMP shut down MySQL Strict Mode Strict Mode

Strict Mode on and off method

Find /etc/my.cnf(windows system is my.ini)

Open

In mysqldincreasing the scopesql_mode = STRICT_TRANS_TABLES

shut down

In mysqldincreasing the scopesql_mode = NO_ENGINE_SUBSTITUTION

Restart

lnmp mysql restart

Temporary modification

mysql -uroot -p
set global sql_mode=''; #会话关闭之后状态修改就消失
select @@sql_mode; #查看模式状态
# 下面两个是网络上的 可以试验一下
#set sql_mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION";
#set sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

Strict Mode Function

  • Not supported not null field to insert null values
  • It does not support self-growth field into the "value
  • It does not support text fields have default values

verification

Create a data table to facilitate testing

select @@sql_mode; #查看模式状态
CREATE TABLE `mytable` (
 `id` int(11) NOT NULL AUTO_INCREMENT,
 `name` varchar(20) NOT NULL,
 `content` text NOT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Non-strict mode

inserting a null value not null field test

insert into mytable(content) values('programmer');
Succeeds, the value of the name is automatically converted to null

From field to insert a null value growth test

insert into mytable(id,name,content) value('','fdipzone','programmer');
Successful execution, id growth since

text field defaults test

CREATE TABLE `mytable_default` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`content` text NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

mysql non-strict mode

In strict mode

inserting a null value not null field test

insert into mytable(content) values('programmer');
ERROR 1364 (HY000): Field ' name' does not have a default value
fails, hint field name is not a null value

From field to insert a null value growth test

insert into mytable(id,name,content) value('','fdipzone','programmer');
ERROR 1366 (HY000): Incorrect integer value: '' for column 'id' at row 1
fails, prompt field id can not be null
insert into mytable(id,name,content) value(null,'fdipzone','programmer');
id is null field can be performed successfully

text field defaults test

CREATE TABLE `mytable_default` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL,
`content` text NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

ERROR 1101 (42000): BLOB / TEXT column 'content' can not have a default value
fails, prompt type content TEXT field is not the default value.
mysql strict mode

to sum up

Use mysql strict mode can make the data more secure strict, the disadvantage is reduced to an empty data storage compatibility. Recommended development environment using strict mode code to improve the quality and rigor of the data.

Guess you like

Origin blog.csdn.net/zycdn/article/details/91490850