使用mysqldump将表数据导出到csv文件中

使用mysqldump将表数据导出到csv文件中

本文介绍了使用mysqldump将表数据导出到csv文件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用mysqldump将表格数据导出到csv文件中。



我想做一些类似的东西:

  mysqldump --compact --no_create_info --tab = testing --fields-enclosed by = \--fields-terminated-by =,-uroot -proot mydatabase mytable 

但我不断收到此错误:

 (Errcode:13)

我使我的测试文件夹可写(我使用Ubuntu作为环境)。可以soneone解释如何导出CSV文件中的表,或如何修改我的命令shell为了工作感谢!

解决方案

所有这些 INTO OUTFILE 或 = tmpfile 的答案是,它需要在MySQL服务器上在同一服务器上运行 mysqldump



我的解决方案只是使用 - > mysql (NOT mysqldump B 参数,使用 -e 内嵌SELECT语句,然后使用 sed


$ b

例如:

  mysql -B -u username -ppassword database -h dbhost -eSELECT * FROM accounts;| seds /'/ \'/; s / \t / \,\ / g; s / ^ / \/; s / $ / \/; s / \\\
// g



添加> outfile.csv ,以获取您的CSV文件。


I want to export a table data into a csv file using mysqldump.

I want to make something like:

mysqldump --compact --no_create_info --tab=testing --fields-enclosed-by=\" --fields-terminated-by=, -uroot -proot mydatabase mytable

but i keep getting this error:

(Errcode: 13) when executing 'SELECT INTO OUTFILE'

I made my testing folder writable(I'm using Ubuntu as enviornment). Can somenone explain how to export a table in a CSV file, or how to modify my command shell in order to work? Thanks!

解决方案

The trouble with all these INTO OUTFILE or --tab=tmpfile answers is that it requires running mysqldump on the same server as the MySQL server.

My solution was simply to use mysql (NOT mysqldump) with the -B parameter, inline the SELECT statement with -e, then massage the ASCII output with sed, and wind up with CSV including a header field row:

Example:

 mysql -B -u username -ppassword database -h dbhost -e "SELECT * FROM accounts;" |sed "s/'/\'/;s/\t/\",\"/g;s/^/\"/;s/$/\"/;s/\n//g"

Add a > outfile.csv at the end of that one-liner, to get your CSV file.

这篇关于使用mysqldump将表数据导出到csv文件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:40