MySQL自己提供了导入导出数据库的工具,但有时我们需要仅仅导入导出单个表的数据,比如导入导出CSV文件,此时可以使用MySQL自动的命令来做导入导出工作。
导入:
LOAD DATA INFILE '[FILE]'
INTO TABLE [TABLE];
或者
LOAD DATA INFILE '[FILE]'
INTO TABLE [TABLE]
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';
导出:
SELECT * FROM [TABLE]
INTO OUTFILE '[FILE]';
或者
SELECT * FROM [TABLE]
INTO OUTFILE '[FILE]'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n';