[英]Exporting mysql data to csv file in the home directory ubuntu
I have a table in mysql and now I am trying to export the entire data into a csv file. 我在mysql中有一个表,现在我正在尝试将整个数据导出到一个csv文件中。 As per the documentation, a possible way of doing this is with the query: 根据文档,执行此操作的一种可能方法是使用查询:
SELECT id, name, email INTO OUTFILE '/tmp/result.csv'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
ESCAPED BY ‘\\’
LINES TERMINATED BY '\n'
FROM users WHERE 1
This works perfectly fine, but it creates the file in my tmp
directory of the filesystem. 这工作得很好,但是它在文件系统的tmp
目录中创建了文件。 I want the file to be in the project directory in my eclipse workspace (I am using java). 我希望文件位于Eclipse工作区的项目目录中(我正在使用Java)。
So, next, what I tried was copying this file to my destination (using apache commons io) and then deleting the file. 因此,接下来,我尝试将文件复制到目的地(使用apache commons io),然后删除该文件。 But I am not able to delete the file ("java.io.IOException: Unable to delete file:", I am assuming this is because I don't have root access to tmp directory). 但是我无法删除该文件(“ java.io.IOException:无法删除文件:”,我认为这是因为我没有对tmp目录的根访问权限)。
Is there any other elegant method of doing what I want...or do I have to use a library like apache POI? 是否有其他优雅的方法可以做我想做的事情...还是必须使用像Apache POI这样的库?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.