在mysql中導(dǎo)出數(shù)據(jù)的命令幾乎都可以導(dǎo)出csv格式的數(shù)據(jù)文件,下面我來給大家舉幾個實例,希望些方法對各位有所幫助.
1.MySQL導(dǎo)出本地數(shù)據(jù)庫數(shù)據(jù)到本地文件,Sql代碼如下:
- load data infile '/tmp/test.csv'
- into table test_info
- fields terminated by ',' optionally enclosed by '"' escaped by '"'
- lines terminated by 'rn';
- //Vevb.com
- load data infile '/tmp/test.csv'
- into table test_info
- fields terminated by ',' optionally enclosed by '"' escaped by '
- "'
lines terminated by 'rn';里面最關(guān)鍵的部分就是格式參數(shù).
2.MySQL導(dǎo)出遠(yuǎn)程數(shù)據(jù)庫數(shù)據(jù)到本地文件,代碼如下:
mysql -A service_db -h your_host -utest -ptest -ss -e "SELECT * from t_apps limit 300;" | sed 's/t/","/g;s/^/"/;s/$/"/;s/n//g' > apps.csv
(sed部分可略,尤其是處理包含漢字的數(shù)據(jù)時).
3.mysqldump導(dǎo)出csv格式的數(shù)據(jù)文件,代碼如下:
# 使用方法如下:mysqldump -uroot -ppassword -t -T/root testdb --fields-enclosed-by=" --fields-terminated-by=,
例:mysqldump -h your_host -utest -ptest -w "id<300" service_db t_apps > tt.sql
導(dǎo)出后格式如下:
"1","m11401","2013-06-22 23:00:01"
"2","m11402","2013-06-22 23:00:02"
"3","m11403","2013-06-22 23:00:03"
新聞熱點
疑難解答
圖片精選