mysql分别用sql和csv文件导入数据

2017-12-02  本文已影响0人  不懒狮Blaise

从sql文件导入:

mysql -uroot -ppwd -D db -Ne "source your.sql"

备份sql文件:

mysqldump -uroot -ppwd db table > db.sql

从csv文件导入(需要进入mysql终端 )

>mysql -uroot -p --local-infile  
LOAD DATA LOCAL INFILE 'E:/csv/hero_list.csv' REPLACE INTO TABLE hero_list FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;
LOAD DATA LOCAL INFILE 'E:/csv/hero_layouts.csv' REPLACE INTO TABLE hero_layouts FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES;
经测试在version: 5.5.46有效,而在5.7.20无效

拷贝数据库重命名为另一个库

mysqldump db1 -u root -ppassword --add-drop-table | mysql newdb -u root -ppassword

上一篇下一篇

猜你喜欢

热点阅读