mysqldump导出数据自增属性丢失案例
create table t9(id int not null auto_increment primary key,name varchar(20) not null default '');
insert into t9 values(1,'a'),(2,'b'),(3,'c');
select * from t9;
mysql> show create table t9 \G
*************************** 1. row ***************************
Table: t9
Create Table: CREATE TABLE `t9` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4
1 row in set (0.00 sec)
mysqldump --single-transaction --set-gtid-purged=off --skip-opt -S /home/data/my3367/socket/mysqld.sock -uroot -proot db2 t9 > t9.sql
--
-- Table structure for table `t9`
--
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `t9` (
`id` int(11) NOT NULL,
`name` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
);
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Dumping data for table `t9`
--
INSERT INTO `t9` VALUES (1,'a');
INSERT INTO `t9` VALUES (2,'b');
INSERT INTO `t9` VALUES (3,'c');
导入后业务处理的时候提示:
DBAPIError exception wrapped from (pymysql.err.InternalError) (1364, u"Field 'id' doesn't have a default value"