V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
husky
V2EX  ›  问与答

mysql 非严格模式插入一条为 null 的数据失败,插入多条就成功,有大佬指点下吗

  •  
  •   husky · 2019-07-12 14:24:13 +08:00 · 1068 次点击
    这是一个创建于 1965 天前的主题,其中的信息可能已经有所发展或是发生改变。
    mysql> status
    --------------
    mysql  Ver 14.14 Distrib 5.7.26, for Linux (x86_64) using  EditLine wrapper
    
    Connection id:		29740
    Current database:
    Current user:		root@localhost
    SSL:			Not in use
    Current pager:		stdout
    Using outfile:		''
    Using delimiter:	;
    Server version:		5.7.26 MySQL Community Server (GPL)
    Protocol version:	10
    Connection:		Localhost via UNIX socket
    Server characterset:	latin1
    Db     characterset:	latin1
    Client characterset:	utf8
    Conn.  characterset:	utf8
    UNIX socket:		/var/lib/mysql/mysql.sock
    Uptime:			6 days 23 hours 30 min 27 sec
    
    Threads: 1  Questions: 1984187  Slow queries: 0  Opens: 1555  Flush tables: 1  Open tables: 947  Queries per second avg: 3.290
    --------------
    
    mysql> SHOW VARIABLES LIKE "sql_mode";
    +---------------+----------------------------------------------------------------------------------------------------+
    | Variable_name | Value                                                                                              |
    +---------------+----------------------------------------------------------------------------------------------------+
    | sql_mode      | NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
    +---------------+----------------------------------------------------------------------------------------------------+
    1 row in set (0.00 sec)
    
    mysql> desc test;
    +----------+------------------+------+-----+---------+----------------+
    | Field    | Type             | Null | Key | Default | Extra          |
    +----------+------------------+------+-----+---------+----------------+
    | id       | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | name     | varchar(255)     | NO   |     |         |                |
    | add_time | int(11)          | NO   |     | 0       |                |
    +----------+------------------+------+-----+---------+----------------+
    3 rows in set (0.00 sec)
    
    mysql> INSERT INTO test (`name`, `add_time`) VALUES ('Albert', NULL);
    ERROR 1048 (23000): Column 'add_time' cannot be null
    mysql> INSERT INTO test (`name`, `add_time`) VALUES ('Albert', NULL),('Ben', NULL);
    Query OK, 2 rows affected, 1 warning (0.03 sec)
    Records: 2  Duplicates: 0  Warnings: 1
    
    mysql> select * from test;
    +----+--------+----------+
    | id | name   | add_time |
    +----+--------+----------+
    |  1 | Albert |        0 |
    |  2 | Ben    |        0 |
    +----+--------+----------+
    2 rows in set (0.00 sec)
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1036 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 20:01 · PVG 04:01 · LAX 12:01 · JFK 15:01
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.