MySQL 不能在mysql工作台中使用日期时间类型

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36078332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 21:39:02  来源:igfitidea点击:

Can not use datetime type in mysql workbench

mysqldatetime

提问by Jaeyoung Lee

I have tried to make a column using datetime type in MySQL workbench.
but, when I select datetime type it occurs an error like

我试图在 MySQL 工作台中使用 datetime 类型制作一列。
但是,当我选择日期时间类型时,会出现类似错误

Could not set new data type The given data type DATETIME contains errors and cannot be accepted. The previous value is kept instead"

无法设置新数据类型 给定的数据类型 DATETIME 包含错误,无法接受。保留以前的值”

How can I use this type?

我怎样才能使用这种类型?

回答by Justin

I had this problem, you need to make sure that when you select the data type you change datetime() to datetime with no ().

我遇到了这个问题,您需要确保在选择数据类型时将 datetime() 更改为不带 () 的 datetime。

From MySQL 5.6.4 onwards DATETIME can have subseconds, the level of precision being defined in the (), if you are not using subseconds then simply remove this all together. This also applies to the TIME and TIMESTAMP Datatypes.

从 MySQL 5.6.4 开始,DATETIME 可以有亚秒,精度级别在 () 中定义,如果您不使用亚秒,那么只需将其全部删除。这也适用于 TIME 和 TIMESTAMP 数据类型。

For more info see here

有关更多信息,请参见此处

回答by Farmer Bob

Re-create the initial workbench connection or reset the advanced connection properties to update the server version. If the server has been upgraded and the workbench connection is not updated the workbench still thinks it is working with the old version and therefore restricts and flags the datetime(x) as an error.

重新创建初始工作台连接或重置高级连接属性以更新服务器版本。如果服务器已经升级并且工作台连接没有更新,工作台仍然认为它正在使用旧版本,因此限制日期时间(x)并将其标记为错误。

回答by Muhammad Faizan Fareed

As of 5.6.4 TIME, TIMESTAMP and DATETIME can have a fractional part. To create a field with subseconds you can specify precision in brackets: TIME(3), DATETIME(6) etc.

从 5.6.4 TIME 开始,TIMESTAMP 和 DATETIME 可以有小数部分。要创建具有亚秒的字段,您可以在括号中指定精度:TIME(3)、DATETIME(6) 等。

time(3)      = 05:05:10.000 (3 precision )
timestamp(6) = 2013-07-04 05:05:10.000000 (6 precision )
datetime(1)  = 2013-07-04 05:05:10.0 (1 precision )
datetime     = 2013-07-04 05:05:10 (0 precision )

回答by user9594796

You need to add a value into the parenthesis. For example, use DATETIME(4) instead of DATETIME().

您需要在括号中添加一个值。例如,使用 DATETIME(4) 而不是 DATETIME()。