MySQL MySQL如何导出特定列的数据
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11631128/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to export a specific column data in MySQL
提问by Jury A
I have a table. I need to export all the rows for 1 column only. How can I achieve this? I know how to export the whole table but have not find a way to export a single columns data.
我有一张桌子。我只需要导出 1 列的所有行。我怎样才能做到这一点?我知道如何导出整个表,但还没有找到导出单列数据的方法。
回答by Jacob
回答by jsist
You can do it very easily using MySQL GUI tools like SQLyog, PHPMyAdmin. In SQLyogyou just need to select the table, Click on "Export As..." Icon and you will get dialog to select the columns that you want to Export. Then click on "Export Button". Export is done...
您可以使用SQLyog、PHPMyAdmin等 MySQL GUI 工具轻松完成此操作。在SQLyog 中,您只需要选择表,单击“导出为...”图标,您将获得对话框以选择要导出的列。然后点击“导出按钮”。导出完成...
Here is the screen shot showing export of column "city" in XML format.
这是显示以 XML 格式导出列“city”的屏幕截图。
Hope it helps...
希望能帮助到你...
回答by jsist
This is for mysql phpmyadmin
这是用于 mysql phpmyadmin
select column_name from table_name
and result set will show now. you can see the tab Query results operations Print view
bottom of the page, the select the export and download which type you want.
结果集现在将显示。您可以看到Query results operations Print view
页面底部的选项卡,选择您想要的导出和下载类型。
回答by devanand
mysql database -e 'select field, field from table' | less
mysql 数据库 -e '选择字段,表中的字段' | 较少的
or into a file.
或放入文件。
On unix it's working.
在 unix 上它正在工作。
all the best
祝一切顺利
回答by vignesh Gunalan
try this..Each result data will be in each row with cell by cell
试试这个..每个结果数据将在每一行中,逐个单元格
SELECT cu.*, cy.name as country_name, st.name as state_name FROM table_name
cu, all_countries cy, all_states st where cu.country = cy.id and cu.state = st.id INTO OUTFILE 'file_info3.csv' FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\t\n'
SELECT cu.*, cy.name as country_name, st.name as state_name FROM table_name
cu, all_countries cy, all_states st where cu.country = cy.id and cu.state = st.id INTO OUTFILE 'file_info3.csv' FIELDS TERMINATED BY ',' 可选地被 '"' 包含在被 '\t\n' 终止的行中
The output file will be located at "C:\wamp\bin\mysql\mysql5.6.17\data\db_name\".
输出文件将位于“C:\wamp\bin\mysql\mysql5.6.17\data\db_name\”。
回答by AyB
For workbench you can do it this way (I'm using MySQL Workbench version 6.3):
对于工作台,您可以这样做(我使用的是 MySQL Workbench 6.3 版):
Right-click on the table and click on "Table Data Export Wizard" which will let you select the columns you want to export:
右键单击表格,然后单击“表格数据导出向导”,您可以选择要导出的列:
It exports as csv or json.
它导出为 csv 或 json。
You can import it back the similar way. (Right-click on the table and click "Table Data Import Wizard"
您可以以类似的方式将其导入回来。(右击表格,点击“表格数据导入向导”
回答by nantitv
Solution from https://www.sitepoint.com/community/t/using-mysqldump-to-export-individual-fields/4743worked for me
来自https://www.sitepoint.com/community/t/using-mysqldump-to-export-individual-fields/4743 的解决方案对我有用
mysql -u USERNAME --password=PASSWORD --database=DATABASE --execute='SELECT FIELD, FIELD FROM TABLE LIMIT 0, 10000 ' -X > file.xml
I tried to export data from a kubernet pod using following query and it worked for me
我尝试使用以下查询从 kubernet pod 导出数据,它对我有用
kubectl exec podName -n namespaceName -- mysql --host=hostName --user=userName --password=password dbName --execute=“SELECT FIELD, FIELD FROM TABLE LIMIT 0, 10000”> a5.sql