MySql 批量创建、导入实例

 

1.创建sql(例如,taobao,dangdang):

DROP DATABASE IF EXISTS taobao;
CREATE DATABASE taobao CHARSET=utf8;
USE taobao;
CREATE TABLE t_product(
id      INT,
name    VARCHAR(20),
pic     VARCHAR(20),
regTime DATETIME,
price   DOUBLE(10,2),
did     INT
);
CREATE TABLE t_ptype(
id INT,
name   VARCHAR(20),
pcount INT
);
INSERT INTO t_ptype VALUES(1,'book',3);
INSERT INTO t_ptype VALUES(2,'dvd',3);
INSERT INTO t_ptype VALUES(3,'cd',1);

INSERT INTO t_product VALUES(1,'b1','1.jpg',now(),100,1);
INSERT INTO t_product VALUES(2,'b2','1.jpg',now(),100,1);
INSERT INTO t_product VALUES(3,'b3','1.jpg',now(),100,1);

INSERT INTO t_product VALUES(4,'dvd1','1.jpg',now(),100,2);
INSERT INTO t_product VALUES(5,'dvd2','1.jpg',now(),100,2);
INSERT INTO t_product VALUES(6,'dvd3','1.jpg',now(),100,2);

INSERT INTO t_product VALUES(7,'cd','1.jpg',now(),100,3);

 

SET NAMES UTF8;
DROP DATABASE IF EXISTS dangdang;
CREATE DATABASE dangdang CHARSET=utf8;
USE dangdang;
CREATE TABLE dd_category(
id      INT,
name    VARCHAR(20),
bcount  INT
);
INSERT INTO dd_category VALUES(100,'计算机类',3);
INSERT INTO dd_category VALUES(200,'历史类',2);
INSERT INTO dd_category VALUES(300,'美食类',1);

CREATE TABLE dd_book(
id      INT,
title   VARCHAR(20),
price   DOUBLE(10,2),
pic     VARCHAR(100),
pubdate DATETIME,
did     INT
);
INSERT INTO dd_book VALUES(1,'计算机1',100,'1.jpg',now(),100);
INSERT INTO dd_book VALUES(2,'计算机2',100,'1.jpg',now(),100);
INSERT INTO dd_book VALUES(3,'计算机3',100,'1.jpg',now(),100);
INSERT INTO dd_book VALUES(4,'历史1',101,'1.jpg',now(),200);
INSERT INTO dd_book VALUES(5,'历史2',101,'1.jpg',now(),200);
INSERT INTO dd_book VALUES(6,'美食',101,'1.jpg',now(),300);

 

2、创建导入sql(例如,test)

SOURCE  d:/taobao.sql
SOURCE  d:/dangdang.sql

 

3、在命令行导入

 

 

这里test.sql文件在d根目录盘下

posted @ 2017-05-08 20:21  快乐的咸鱼  阅读(353)  评论(0编辑  收藏  举报