近期接到需求,导出百万级数据库数据,因为阿里云数据库是免费版,导出有限制,所以得用shell导出
1. 数据准备
INSERT into articles(title,subhead,type,slug,content,thumb_img,seo_title,seo_description) SELECT title,subhead,type,slug,content,thumb_img,seo_title,seo_description from articles
表信息
CREATE TABLE `articles` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`subhead` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`url` varchar(255) COLLATE utf8_unicode_ci DEFAULT '/' COMMENT '跳转地址',
`type` int(4) DEFAULT NULL,
`slug` varchar(255) COLLATE utf8_unicode_ci DEFAULT '' COMMENT '链接显示',
`is_del` tinyint(4) DEFAULT NULL,
`content` text COLLATE utf8_unicode_ci,
`thumb_img` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',
`seo_title` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',
`seo_keywords` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',
`seo_description` varchar(255) COLLATE utf8_unicode_ci DEFAULT '',
`sort` int(11) DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
导出数据到csv
mysqldump -uroot -p wxshop articles> shunde.csv
[root@localhost ~]# ll
总用量 343300
-rw-------. 1 root root 1523 2月 3 19:42 anaconda-ks.cfg
-rw-r--r--. 1 root root 1551 2月 3 11:48 initial-setup-ks.cfg
drwxr-xr-x 9 root root 233 3月 1 08:51 ncov
-rw-r--r-- 1 root root 315 3月 4 13:52 p.json
drwxr-xr-x 4 root root 35 4月 3 18:44 Playground
-rw-r--r-- 1 root root 351524740 6月 7 09:42 shunde.csv
drwxr-xr-x 3 root root 23 6月 5 09:55 var
文件分割用splist
split -n 500000 shunde.csv