Solved

backing up data that matches certain criteria

Posted on 2010-11-16
7
317 Views
Last Modified: 2012-05-10
Hi

Using mysql backup tools, is it possible to do something like a mysqldump for rows in a table that match certain criteria.

For example, lets say I have a database that has table A with 100 records. Table A has a field called TestValue. 50 records have a value 10 in this field and the rest have a value 20 in this field.

This is what I want to do:

1) Create a mysql dump for the 50 records where TestValue = 20
2) Delete the records where TestValue = 20
3) At a later date, restore from the mysql dump the 50 records where TestValue = 20 so that Table A has 100 records in it again

Basically the reason I am thinking of this solution is that I have a database that contains a mixture of public and private data. When this data is 'inhouse' both the public and private data should be in the database. The database can be sent out into the public domain and the private data must be removed. The database may well be returned to us with extra data in it. The private data then needs to be restored when it is back inhouse.

My solution to this was a 'selective' mysql dump but I'm not a database person so there may be a better option. My idea may not even be possible

thanks a lot
0
Comment
Question by:andieje
  • 4
  • 2
7 Comments
 
LVL 27

Expert Comment

by:yodercm
ID: 34150149
Have you considered creating a temporary table containing only the data you want to backup, then using the dump on the temporary table?
0
 

Author Comment

by:andieje
ID: 34151403
i was hoping i could just back up parts of the relevant table without having to create a temporary table. Then i could reinstate the data back to the temporary table rather than having to reinstate the data into the temporary table and then move it from the temporary table to the original table.

It seemed simpler that way to me
0
 

Author Comment

by:andieje
ID: 34151613
how about doing a 'select into' statement on the table rows that I want and then import these back in using a mysqlimport statement?

Any other solutions welcomed
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 34154434
please see this option in the MySQLDUMp tool:
http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html
--where='where_condition'       where       Dump only rows selected by the given WHERE condition
0
 

Author Comment

by:andieje
ID: 34154700
that drops the table and all the data in it though doesnt it?

i can use that with the no-create-db and no-create-info options i guess then?
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34154714
yes, exactly
0
 

Author Closing Comment

by:andieje
ID: 34155348
thanks
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql_mode 1 24
How to import sql database into mysql workbench 18 36
Excel - SQL export question 3 42
mysql disables rename 4 73
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

810 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