來自:
匯出
select*from
test_info
into outfile '
/tmp/test.csv
'fields terminated by'
,' optionally enclosed by'"
' escaped by'"
'lines terminated by'
\r\n
';
匯入
load data infile '/tmp/test.csv
'into
table
test_info
fields terminated by'
,' optionally enclosed by'"
' escaped by'"
'lines terminated by'
\r\n
';
其中關鍵引數是
fields terminated by',' optionally enclosed by'"
' escaped by'"
'lines terminated by'
\r\n
'
這個引數是根據rfc4180文件設定的,該文件全稱common format and mime type for comma-separated values (csv) files,其中詳細描述了csv格式,其要點包括:
(1)字段之間以逗號分隔,資料行之間以\r\n分隔;
(2)字串以半形雙引號包圍,字串本身的雙引號用兩個雙引號表示。
shell 例子
#!/bin/sh. /opt/shtools/commons/mysql.sh
# mysql_csv_format="
fields terminated by ',' optionally enclosed by '\"' escaped by '\"' lines terminated by '\r\n'
"echo
"mysql_csv_format=$mysql_csv_format
"rm /tmp/test.csv
mysql -p --default-character-set=gbk -t --verbose test
P S 向MySQL中匯入CSV檔案
load data infile g adawn com.facebook.katana2.csv ignore 注意,這裡的ignore是關鍵,不匯入重複的行 fields terminated by enclosed by lines terminated by r n csv檔案row之間以 ...
MySQL匯入匯出CSV檔案
mysql自己提供了匯入匯出資料庫的工具,但有時我們需要僅僅匯入匯出單個表的資料,比如匯入匯出csv檔案,此時可以使用mysql自動的命令來做匯入匯出工作。匯出語法如下 select from table into outfile file 或者select from table into outf...
MySQL匯入匯出CSV檔案
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!mysql自己提供了匯入匯出資料庫的工具,但有時我們需要僅僅匯入匯出單個表的資料,比如匯入匯出csv檔案,此時可以使用mysql自動的命令來做匯入匯出工作。匯出語法如下 select from table into outfile file 或者s...