?
Solved

MySQL: Create Dump From Select Query

Posted on 2011-09-16
6
Medium Priority
?
419 Views
Last Modified: 2012-05-12
I want to create a SQL dump that I can use to manually import the selected records to another database.

How can this query be modified to create SQL text that could be used for the dump?
select * from elqBooks WHERE `isbn` like '9780813343310'

Open in new window

0
Comment
Question by:hankknight
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 12

Expert Comment

by:viralypatel
ID: 36550741
goto "view" menu and select view as text instead of view as grid.

You'll get the output as text...
0
 
LVL 16

Author Comment

by:hankknight
ID: 36550765
This is a MySQL question.  I use MySQL from a command line.  There is no menu view.
0
 
LVL 79

Assisted Solution

by:arnold
arnold earned 600 total points
ID: 36550795
http://www.tech-recipes.com/rx/1475/save-mysql-query-results-into-a-text-or-csv-file/

Excerpt from the link
SELECT order_id,product_name,qty
FROM orders
INTO OUTFILE '/tmp/orders.csv'
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'

Open in new window

0
Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

 
LVL 16

Author Comment

by:hankknight
ID: 36550847
Can I do this without manually defining the columns, and can the output be SQL instead of CSV?
0
 
LVL 79

Expert Comment

by:arnold
ID: 36550958
Can you explain what you mean by SQL?

select * from elqBooks WHERE `isbn` like '9780813343310'
INTO OUTFILE '/tmp/elqbooks.txt'

This will likely be a tab separated data (tsv) data format.
Do you need it to have | as separator (fields terminated by '|')


0
 
LVL 25

Accepted Solution

by:
Tomas Helgi Johannsson earned 1400 total points
ID: 36551721
                 Hi!

If you want to extract particular data from a table into a file which has the data surrounded by INSERT statement then you
use the mysqldump program with the where option
See the manual :)
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_where

So this command for you would be something like this
mysqldump -t -u [username] -p test elqBooks --where="isbn` like '9780813343310'"
see more examples here
http://www.electrictoolbox.com/mysqldump-selectively-dump-data/

Hope this helps.
Regards,
    Tomas Helgi
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
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…
Suggested Courses

765 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