导出命令:
mysql> SELECT * FROM passwd INTO OUTFILE '/tmp/runoob.txt' -> FIELDS TERMINATED BY ',' ENCLOSED BY '"' -> LINES TERMINATED BY '\n';
##将passwd这张表的数据全部导出到/tmp/runoob.txt文件中,这个也可以是csv格式
导入命令:
LOAD DATA [LOW_PRIORITY | CONCURRENT] [LOCAL] INFILE 'file_name' [REPLACE | IGNORE] INTO TABLE tbl_name [PARTITION (partition_name [, partition_name] ...)] [CHARACTER SET charset_name] [{FIELDS | COLUMNS} [TERMINATED BY 'string'] [[OPTIONALLY] ENCLOSED BY 'char'] [ESCAPED BY 'char'] ] [LINES [STARTING BY 'string'] [TERMINATED BY 'string'] ] [IGNORE number {LINES | ROWS}] [(col_name_or_user_var [, col_name_or_user_var] ...)] [SET col_name={expr | DEFAULT} [, col_name={expr | DEFAULT}] ...]
##这个是将/tmp目录下的t.csv文件导入到数据库的某张表下(后面与上面的导出时的格式保持一致)
mysql>>load data infile '/tmp/t.csv' into table tb_name FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n';
##特别说明一下:以上两个命令是在mysql中执行,不是在linux命令行中执行,务必注意!!!!!