MySQL 无法使用 '2014-10-19 00:00:00' 更新 TIMESTAMP 字段

标签 mysql

我有一个 TIMESTAMP 字段,但它不接受值 2014-10-19 00:00:00

我使用的是 MySQL 5.6,并且我在 Windows 和 Linux 版本中都进行了测试。

如果第一种格式不被接受,我应该写什么?

最佳答案

create table thing9
(   id int auto_increment primary key,
    theWhat varchar(80) not null,
    theWhen timestamp not null
);
insert thing9(theWhat,theWhen) values('fish','2014-10-19 00:00:00');
insert thing9(theWhat,theWhen) values('fish','2012-10-19 00:00:00');
insert thing9(theWhat,theWhen) values('fish','2016-10-19 00:00:00');

update thing9 set theWhen='2011-10-19 00:00:00' where id=2;

+----+---------+---------------------+
| id | theWhat | theWhen             |
+----+---------+---------------------+
|  1 | fish    | 2014-10-19 00:00:00 |
|  2 | fish    | 2011-10-19 00:00:00 |
|  3 | fish    | 2016-10-19 00:00:00 |
+----+---------+---------------------+

mysql> show variables like '%versi%';
+-------------------------+------------------------------+
| Variable_name           | Value                        |
+-------------------------+------------------------------+
| innodb_version          | 5.6.24                       |
| protocol_version        | 10                           |
| slave_type_conversions  |                              |
| version                 | 5.6.24-log                   |
| version_comment         | MySQL Community Server (GPL) |
| version_compile_machine | x86_64                       |
| version_compile_os      | Win64                        |
+-------------------------+------------------------------+

编辑:

我想知道您是否有 mysql 时区的问题。请查看Mysql手册页链接here ,下面是其中的一小段摘录。

mysql> SELECT @@global.time_zone, @@session.time_zone; timezone values can be given in several formats, none of which are case sensitive:

The value 'SYSTEM' indicates that the time zone should be the same as the system time zone.

The value can be given as a string indicating an offset from UTC, such as '+10:00' or '-6:00'.

编辑2:

show variables where variable_name like '%datetime%'
+-----------------+-------------------+
| Variable_name   | Value             |
+-----------------+-------------------+
| datetime_format | %Y-%m-%d %H:%i:%s |
+-----------------+-------------------+

如果您的顺序是 D-M-Y 或其他顺序,请根据情况进行更改。

关于MySQL 无法使用 '2014-10-19 00:00:00' 更新 TIMESTAMP 字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32156795/

相关文章:

mysql - 如何搜索以包含 % 和 _ 字符的另一个值开头或结尾的值?

mysql - 如何在状态为 2 的 mysql 中使用 if 条件

php - 统计查询结果,根据结果显示信息,点击按钮后使用ajax刷新页面显示信息

mysql - 为什么从 MySQL 5.5 迁移到 5.7 会拒绝连接?

mysql - 我需要从 3 个分类法(个人资料类别、县、部门)获取帖子数据

php - mysql案例然后无法识别的关键字和无法识别的 token

php - mysql:使用另一个表的数据对表行进行排序

php - 在非对象上调用成员函数bind_param()?那我该怎么办?

mysql - Cloud SQL 访问被拒绝

Mysql if语句忽略第一个条件