mysqldump

Reply

Join Date: Nov 2008
Posts: 3
Reputation: andrei4002 is an unknown quantity at this point 
Solved Threads: 0
andrei4002 andrei4002 is offline Offline
Newbie Poster

mysqldump

 
0
  #1
Sep 7th, 2009
hello everyone.

i have a program that writes into a mysql database, and at some time, i have to do some sort of database rotation
that's like a dump followed by a truncate (at least it's how I see it)
the problem is that while i do the dump, that program is very likely to write into the database and after the dump finishes, if i truncate the tables i might lose some lines (the ones added during the dump)
i know i can set mysqldump to lock the tables, but after the dump ends it releases them and the problem of the program inserting lines before the truncate starts appears once more (it may add even a few lines before it actually does the truncate, and then I lose them with the truncate)

practically i want to backup a database (periodically) to a file and then clear the database, without losing any intermediate data inserted into it

is there any way to solve this?
Last edited by andrei4002; Sep 7th, 2009 at 9:44 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 821
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 135
Sponsor
pritaeas's Avatar
pritaeas pritaeas is offline Offline
Practically a Posting Shark

Re: mysqldump

 
0
  #2
Sep 7th, 2009
If you are using a different user for the dump, than you could disallow priviliges to the general user, while dumping/truncating, and reset priviliges afterwards.

"FLUSH TABLES WITH READ LOCK" may be a better option. But haven't used it myself.
Last edited by pritaeas; Sep 7th, 2009 at 10:46 am.
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 823
Reputation: verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough verruckt24 is a jewel in the rough 
Solved Threads: 73
verruckt24's Avatar
verruckt24 verruckt24 is offline Offline
Practically a Posting Shark

Re: mysqldump

 
0
  #3
Sep 9th, 2009
Firstly is there any criteria as to on which you could separate the data ?
Say for example if there is any auto_increment field you could certainly use this to tuncate only those rows with id <= last_id, if not is there any timestamp value which could be used in the same way.
If there are such fields it would most rightly serve you to take the dump without locking the tables and then truncating accordingly, since locks are always going to hinder performance. Also if the dump takes a lot of time to finish, other insert/update processes might get a "lockwait timeout exceed"

If the above is not feasible due to absence of such a column on which rows could easily be separated, then what you could do is before starting with the mysqldump, create a table identical to the original one with the 'CREATE TABLE %tablename%... AS SELECT * from %originaltablename%' syntax then run mysqldump on this table and then finally drop the duplicate table. This wouldn't require locking at all (apart from the one that the mysql server itself would enforce while creating the table) and inserts could go on on the original table while you are taking the mysldump of the duplicate table.

If both the above mentioned options aren't feasible to you, you could use explicit locking on tables during the mysqldump and truncate commands and release them only after the truncate command has finished.
Get up every morning and take a look at the Forbes' list of richest people. If your name doesn't appear.... GET TO WORK !!!
Reply With Quote Quick reply to this message  
Reply

Message:



Similar Threads
Other Threads in the MySQL Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC