Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way to archive live MySQL database

Tags:

database

mysql

We have a live MySQL database that is 99% INSERTs, around 100 per second. We want to archive the data each day so that we can run queries on it without affecting the main, live database. In addition, once the archive is completed, we want to clear the live database.

What is the best way to do this without (if possible) locking INSERTs? We use INSERT DELAYED for the queries.

like image 202
davidmytton Avatar asked Sep 15 '08 17:09

davidmytton


People also ask

How do I archive a MySQL database?

Another option for archiving MySQL data is a tool like pt-archiver. pt-archiver is a component of the Percona Toolkit that nibbles old data from a source table and moves it to a target table. The target can be in the current or an archive database. It is designed for use with an up-and-running database.

Does MySQL have TTL?

No, you need to DELETE the data when it's expired. You can implement something similar by adding a DATETIME field and run a scheduled task in your operating system (a cronjob on Unix-like systems). You can even schedule it directly in MySQL: MySQL Manual: Using the Event Scheduler.

How do you archive a database?

Select Database | Manage Database Backup and Restore. In the upper right Databases pane, select the full STORAGE database you wish to archive. The database must have reached its maximum size, and a new database must be started. Right-click the STORAGE database and select Archive.

When should you archive a database?

Data archiving is most suitable for data that must be retained due to operational or regulatory requirements, such as document files, email messages and possibly old database records.


1 Answers

http://www.maatkit.org/ has mk-archiver

archives or purges rows from a table to another table and/or a file. It is designed to efficiently “nibble” data in very small chunks without interfering with critical online transaction processing (OLTP) queries. It accomplishes this with a non-backtracking query plan that keeps its place in the table from query to query, so each subsequent query does very little work to find more archivable rows.

Another alternative is to simply create a new database table each day. MyIsam does have some advantages for this, since INSERTs to the end of the table don't generally block anyway, and there is a merge table type to being them all back together. A number of websites log the httpd traffic to tables like that.

With Mysql 5.1, there are also partition tables that can do much the same.

like image 181
Alister Bulman Avatar answered Sep 28 '22 11:09

Alister Bulman