MySql 批量創建、導入實例
阿新 • • 發佈:2017-05-08
alt clas font category color cat bold log class
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), pcountINT ); 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); INSERTINTO 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根目錄盤下
MySql 批量創建、導入實例