<i id='W91gR'><tr id='W91gR'><dt id='W91gR'><q id='W91gR'><span id='W91gR'><b id='W91gR'><form id='W91gR'><ins id='W91gR'></ins><ul id='W91gR'></ul><sub id='W91gR'></sub></form><legend id='W91gR'></legend><bdo id='W91gR'><pre id='W91gR'><center id='W91gR'></center></pre></bdo></b><th id='W91gR'></th></span></q></dt></tr></i><div id='W91gR'><tfoot id='W91gR'></tfoot><dl id='W91gR'><fieldset id='W91gR'></fieldset></dl></div>

<small id='W91gR'></small><noframes id='W91gR'>

      <bdo id='W91gR'></bdo><ul id='W91gR'></ul>

      <tfoot id='W91gR'></tfoot>

      <legend id='W91gR'><style id='W91gR'><dir id='W91gR'><q id='W91gR'></q></dir></style></legend>

      1. MySQL 不正确的日期时间值:'0000-00-00 00:00:00'

        MySQL Incorrect datetime value: #39;0000-00-00 00:00:00#39;(MySQL 不正确的日期时间值:0000-00-00 00:00:00)

        1. <legend id='lfU0h'><style id='lfU0h'><dir id='lfU0h'><q id='lfU0h'></q></dir></style></legend>

          <tfoot id='lfU0h'></tfoot>

          <small id='lfU0h'></small><noframes id='lfU0h'>

              <tbody id='lfU0h'></tbody>
              <bdo id='lfU0h'></bdo><ul id='lfU0h'></ul>
                  <i id='lfU0h'><tr id='lfU0h'><dt id='lfU0h'><q id='lfU0h'><span id='lfU0h'><b id='lfU0h'><form id='lfU0h'><ins id='lfU0h'></ins><ul id='lfU0h'></ul><sub id='lfU0h'></sub></form><legend id='lfU0h'></legend><bdo id='lfU0h'><pre id='lfU0h'><center id='lfU0h'></center></pre></bdo></b><th id='lfU0h'></th></span></q></dt></tr></i><div id='lfU0h'><tfoot id='lfU0h'></tfoot><dl id='lfU0h'><fieldset id='lfU0h'></fieldset></dl></div>
                  本文介绍了MySQL 不正确的日期时间值:'0000-00-00 00:00:00'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我最近接手了一个 10 年前创建的旧项目.它使用 MySQL 5.1.

                  I've recently taken over an old project that was created 10 years ago. It uses MySQL 5.1.

                  除此之外,我需要将默认字符集从 latin1 更改为 utf8.

                  Among other things, I need to change the default character set from latin1 to utf8.

                  举个例子,我有这样的表格:

                  As an example, I have tables such as this:

                    CREATE TABLE `users` (
                      `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
                      `first_name` varchar(45) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
                      `last_name` varchar(45) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
                      `username` varchar(127) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
                      `email` varchar(127) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
                      `pass` varchar(20) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL,
                      `active` char(1) CHARACTER SET latin1 COLLATE latin1_general_ci NOT NULL DEFAULT 'Y',
                      `created` datetime NOT NULL,
                      `last_login` datetime DEFAULT NULL,
                      `author` varchar(1) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT 'N',
                      `locked_at` datetime DEFAULT NULL,
                      `created_at` datetime DEFAULT NULL,
                      `updated_at` datetime DEFAULT NULL,
                      `ripple_token` varchar(36) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
                      `ripple_token_expires` datetime DEFAULT '2014-10-31 08:03:55',
                      `authentication_token` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_ci DEFAULT NULL,
                      PRIMARY KEY (`id`),
                      UNIQUE KEY `index_users_on_reset_password_token` (`reset_password_token`),
                      UNIQUE KEY `index_users_on_confirmation_token` (`confirmation_token`),
                      UNIQUE KEY `index_users_on_unlock_token` (`unlock_token`),
                      KEY `users_active` (`active`),
                      KEY `users_username` (`username`),
                      KEY `index_users_on_email` (`email`)
                    ) ENGINE=InnoDB AUTO_INCREMENT=1677 DEFAULT CHARSET=utf8 CHECKSUM=1 DELAY_KEY_WRITE=1 ROW_FORMAT=DYNAMIC
                  

                  我设置了自己的 Mac 来处理这个问题.没有考虑太多,我运行了安装 MySQL 5.7 的brew install mysql".所以我有一些版本冲突.

                  I set up my own Mac to work on this. Without thinking too much about it, I ran "brew install mysql" which installed MySQL 5.7. So I have some version conflicts.

                  我下载了该数据库的副本并将其导入.

                  I downloaded a copy of this database and imported it.

                  如果我尝试运行这样的查询:

                  If I try to run a query like this:

                    ALTER TABLE users MODIFY first_name varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci    NOT NULL  
                  

                  我收到此错误:

                    ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'created' at row 1
                  

                  我想我可以解决这个问题:

                  I thought I could fix this with:

                    ALTER TABLE users MODIFY created datetime  NULL DEFAULT '1970-01-01 00:00:00';
                    Query OK, 0 rows affected (0.06 sec)
                    Records: 0  Duplicates: 0  Warnings: 0
                  

                  但我得到:

                    ALTER TABLE users MODIFY first_name varchar(45) CHARACTER SET utf8 COLLATE utf8_general_ci    NOT NULL ;
                    ERROR 1292 (22007): Incorrect datetime value: '0000-00-00 00:00:00' for column 'created' at row 1
                  

                  我是否必须更新每个值?

                  Do I have to update every value?

                  推荐答案

                  我的建议,如果是空表或不是很大的情况,将create语句导出为.sql文件,按照你的方式重写希望.如果您有任何现有数据,也请执行相同操作,即导出插入语句(我建议在单独的文件中执行此操作作为创建语句).最后删除表,先执行create语句再插入.

                  My suggestion if it is the case that the table is empty or not very very big is to export the create statements as a .sql file, rewrite them as you wish. Also do the same if you have any existing data, i.e. export insert statements (I recommend doing this in a separate file as the create statements). Finally, drop the table and execute first create statement and then inserts.

                  您可以使用 mysqldump 命令,包含在您的 MySQL 安装中,或者您也可以安装 MySQL Workbench,这是一个免费的图形工具,它也以非常可定制的方式包含此选项,而无需寻找特定的命令选项.

                  You can use for that either mysqldump command, included in your MySQL installation or you can also install MySQL Workbench, which is a free graphical tool that includes also this option in a very customisable way without having to look for specific command options.

                  这篇关于MySQL 不正确的日期时间值:'0000-00-00 00:00:00'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Bogus foreign key constraint fail(虚假外键约束失败)
                  how to get last insert id after insert query in codeigniter active record(如何在codeigniter活动记录中插入查询后获取最后一个插入ID)
                  Force InnoDB to recheck foreign keys on a table/tables?(强制 InnoDB 重新检查表/表上的外键?)
                  How to auto generate migrations with Sequelize CLI from Sequelize models?(如何使用 Sequelize CLI 从 Sequelize 模型自动生成迁移?)
                  Clear MySQL query cache without restarting server(无需重启服务器即可清除 MySQL 查询缓存)
                  ALTER TABLE to add a composite primary key(ALTER TABLE 添加复合主键)
                  <tfoot id='B29j9'></tfoot>

                  <legend id='B29j9'><style id='B29j9'><dir id='B29j9'><q id='B29j9'></q></dir></style></legend>
                1. <small id='B29j9'></small><noframes id='B29j9'>

                    <tbody id='B29j9'></tbody>

                  • <bdo id='B29j9'></bdo><ul id='B29j9'></ul>

                      1. <i id='B29j9'><tr id='B29j9'><dt id='B29j9'><q id='B29j9'><span id='B29j9'><b id='B29j9'><form id='B29j9'><ins id='B29j9'></ins><ul id='B29j9'></ul><sub id='B29j9'></sub></form><legend id='B29j9'></legend><bdo id='B29j9'><pre id='B29j9'><center id='B29j9'></center></pre></bdo></b><th id='B29j9'></th></span></q></dt></tr></i><div id='B29j9'><tfoot id='B29j9'></tfoot><dl id='B29j9'><fieldset id='B29j9'></fieldset></dl></div>