mysql怎么导出csv格式数据文件
1个回答
展开全部
1.MySQL导出本地数据库数据到本地文件
Sql代码
代码如下 复制代码
load data infile '/tmp/test.csv'
into table test_info
fields terminated by ',' optionally enclosed by '"' escaped by '"'
lines terminated by 'rn';
load data infile '/tmp/test.csv'
into table test_info
fields terminated by ',' optionally enclosed by '"' escaped by '
"'
lines terminated by 'rn'; 里面最关键的部分就是格式参数
2.MySQL导出远程数据库数据到本地文件
代码如下 复制代码
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部分可略,尤其是处理包含汉字的数据时)
3. mysqldump导出csv格式的数据文件
代码如下 复制代码
# 使用方法如下
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
导出后格式如下:
代码如下 复制代码
"1","m11401","2013-06-22 23:00:01"
"2","m11402","2013-06-22 23:00:02"
"3","m11403","2013-06-22 23:00:03"
Sql代码
代码如下 复制代码
load data infile '/tmp/test.csv'
into table test_info
fields terminated by ',' optionally enclosed by '"' escaped by '"'
lines terminated by 'rn';
load data infile '/tmp/test.csv'
into table test_info
fields terminated by ',' optionally enclosed by '"' escaped by '
"'
lines terminated by 'rn'; 里面最关键的部分就是格式参数
2.MySQL导出远程数据库数据到本地文件
代码如下 复制代码
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部分可略,尤其是处理包含汉字的数据时)
3. mysqldump导出csv格式的数据文件
代码如下 复制代码
# 使用方法如下
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
导出后格式如下:
代码如下 复制代码
"1","m11401","2013-06-22 23:00:01"
"2","m11402","2013-06-22 23:00:02"
"3","m11403","2013-06-22 23:00:03"
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询