Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

export field to text file from mysqldump cli / ubuntu 10

Posted on 2011-09-07
7
Medium Priority
?
632 Views
Last Modified: 2012-05-12
Using:
Ubuntu 10.10
mysql  Ver 14.14 Distrib 5.1.49, for debian-linux-gnu (i686) using readline 6.1
mysqldump

I need to export a field from a table into a text file and have the following format:

line 1
line 2
line 3
line n
0
Comment
Question by:_3mp3ror_
  • 3
  • 2
  • 2
7 Comments
 
LVL 7

Expert Comment

by:jackiechen858
ID: 36497963
try
mysqldump -T/tmp/ databasename tablename -pDatabasepassword

This will create two files in /tmp/ folder:

tablename.sql the SQL query to create the table.
tablename.txt, a text file with all the data in this table.

For some reason, on my Ubuntu machine, the first file is created by user root, the second txt file is created by user mysql, so make sure mysql user have permission to the output directory set by -T ( i use /tmp/, so mysql user has enough permission.)


0
 
LVL 8

Accepted Solution

by:
stalhw earned 1000 total points
ID: 36498062
mysqldump won't allow you to output only one field (column)...
But the mysql CLI tools will, try something like:

mysql -e "select yourField from yourTable" -u myuser -pxxxxxxxxx mydatabase > yourdumpfile.txt
0
 
LVL 9

Author Comment

by:_3mp3ror_
ID: 36498295
stalhw your method worked

mysql -e "SELECT field FROM table" --default-character-set=utf8 -u user -pxxxxxx database > dump.txt as i also had some eastern european charset

but what is the syntax needed so that I don't get the field name on the first line in the dump file ?

 
0
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
LVL 8

Expert Comment

by:stalhw
ID: 36498495
I think it's  --skip-column-names
0
 
LVL 7

Expert Comment

by:jackiechen858
ID: 36498499
mysql -e "SELECT field FROM table" --default-character-set=utf8 -u user -pxxxxxx | tail  -n+2  >dump.txt
0
 
LVL 7

Expert Comment

by:jackiechen858
ID: 36498513
oh yeah, there is a --skip-column-names, this one is better.
0
 
LVL 9

Author Closing Comment

by:_3mp3ror_
ID: 36498802
Perfect, thanks.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lotus Notes has been used since a very long time as an e-mail client and is very popular because of it's unmatched security. In this article we are going to learn about  RRV Bucket corruption and understand various methods to Fix "RRV Bucket Corrupt…
In this article, I’ll look at how you can use a backup to start a secondary instance for MongoDB.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question