简体   繁体   中英

How to fix MySql database restore error using Wordpress UpdraftPlus: Error Code: 1067. Invalid default value for 'user_registered'

When running my Wordpress UpdraftPlus database restore script I get the error Error Code: 1067. Invalid default value for 'user_registered'

I tried prefixing the script with

SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
drop database wordpress;
create database wordpress;
use wordpress;

as suggested here: https://wordpress.org/support/topic/invalid-default-value-database-install-fail/ but it doesn't make a difference.

The part of the script giving the error is CREATE TABLE wp_users ( ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, user_login varchar(60) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', user_pass varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', user_nicename varchar(50) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', user_email varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', user_url varchar(100) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', user_registered datetime NOT NULL DEFAULT '0000-00-00 00:00:00', user_activation_key varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', user_status int(11) NOT NULL DEFAULT '0', display_name varchar(250) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '', PRIMARY KEY ( ID ), KEY user_login_key ( user_login ), KEY user_nicename ( user_nicename ), KEY user_email ( user_email ) ) ENGINE=MyISAM AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

According to the documentation ,

Setting the GLOBAL variable requires the SUPER privilege and affects the operation of all clients that connect from that time on. Setting the SESSION variable affects only the current client.

So to just create your table, either reconnect or set the session variable.

But both ways will only have temporary affect, because after a server restart, your settings will be reset to the default values, and you won't be able to insert new users to the table anymore.

So after you tested the setting, you will have to set the value in your config file (eg my.cnf ). You should also only remove the option that is causing you trouble, which is either the depreciated NO_ZERO_DATE or STRICT_TRANS_TABLES .

So for a 5.7.8+ default configuration, add under [mysqld]

sql_mode='ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

to your config file and restart your server.

For MySQL 5.7.4 to 5.7.7, you would have to remove the STRICT_TRANS_TABLES instead, because NO_ZERO_DATE has no affect (and will have no affect again in some future version).

You might have to remove further options, a usual suspect is often ONLY_FULL_GROUP_BY , but only remove it if you run into problems with wordpress.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM