Solved

export field to text file from mysqldump cli / ubuntu 10

Posted on 2011-09-07
7
601 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
Comment Utility
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 250 total points
Comment Utility
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_
Comment Utility
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
Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

 
LVL 8

Expert Comment

by:stalhw
Comment Utility
I think it's  --skip-column-names
0
 
LVL 7

Expert Comment

by:jackiechen858
Comment Utility
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
Comment Utility
oh yeah, there is a --skip-column-names, this one is better.
0
 
LVL 9

Author Closing Comment

by:_3mp3ror_
Comment Utility
Perfect, thanks.
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…

762 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now