如何在mysql中导出csv文件到我的电脑 [英] How do I export csv file to my computer in mysql

查看:377
本文介绍了如何在mysql中导出csv文件到我的电脑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试以csv格式将表从远程服务器导出到我的桌面计算机。我有这个代码:

I am trying to export a table from a remote server to my desktop computer in csv format. I have this code:

select * from order
into outfile 'C:\Users\Sleep Shop\Desktop\MySQL Scripts/outfile.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\n';

但我收到此错误:

failed : Can't create/write to file '/var/lib/mysql/C:\Users\Sleep Shop\Desktop\MySQL Scripts/outfile.csv' (Errcode: 2)

我认为有一些基本的东西我不明白

I'm thinking there is something fundamental I don't understand about this procedure, probably something to do the table being at a remote server. Can anyone help?

更新到问题:
我使用这个代码来告诉一个在服务器上创建文件:

UPDATE TO PROBLEM: I used this code to tell a spot on the server to create the file:

select * from orders
into outfile'/var/www/test/outfile.csv'
FIELDS TERMINATED BY','
ENCLOSED BY'
ESCAPED BY'\'
由'\\\
'终止的字符串

select * from orders into outfile '/var/www/test/outfile.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\' LINES TERMINATED BY '\n';

它创建文件,但它不包含记录,我收到此错误:

It creates the file but it contains no records and I get this error:

失败:字段分隔符参数不是预期的;

failed : Field separator argument is not what is expected;

推荐答案

更改查询如下:

select * from `order`
into outfile 'export.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n';


您将在远程服务器的目录中找到该文件:/var/lib/mysql/export.csv(或可能是/var/lib/mysql/data/your-db-name/export.csv)

Then you will find the file in your remote server's directory here: /var/lib/mysql/export.csv (or possibly /var/lib/mysql/data/your-db-name/export.csv)

通过SSH连接到您的服务器(使用putty ),并将文件传输到PC或将文件移动到接受FTP访问的目录,您可以使用FTP客户端(即filezilla,winSCP)下载它。

Connect to your server via SSH (use putty) and transfer the file to your PC or move the file to a directory that accepts FTP access and you can download it using an FTP client (ie. filezilla, winSCP).

或者您可以使用phpMyAdmin并点击表格,然后点击导出标签,然后您将看到一个选项,从格式下拉菜单中选择CSV如果你的表太大(取决于phpMyAdmin的设置或PHP的设置脚本可以运行多长时间),这可能不工作。

Or you can use phpMyAdmin and click on the table, then click the "export" tab, and then you will see an option to select "CSV" from the format dropdown. This may not work if your table is too large (depends on phpMyAdmin's settings or PHP's settings on how long a script can run).

这篇关于如何在mysql中导出csv文件到我的电脑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆