Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql database automatic partitioning

Tags:

I have a mysql database table that I want to partition by date, particularly by month & year. However, when new data is added for a new month, I don't want to need to manually update the database.

When I initially create my database, I have data in Nov 09, Dec 09, Jan 10, etc. Now when February starts, I'd like a Feb 10 partition automatically created. Is this possible?

like image 379
Jeff Storey Avatar asked Feb 01 '10 01:02

Jeff Storey


People also ask

What is automatic partitioning?

Auto-partitioning, in networking, is an Ethernet component used as a safety net to prevent corrupt data transmission and data loss while isolating defective devices, ports, or network lines.

Does MySQL support data partitioning?

MySQL supports several types of partitioning as well as subpartitioning; see Section 22.2, “Partitioning Types”, and Section 22.2. 6, “Subpartitioning”. Section 22.3, “Partition Management”, covers methods of adding, removing, and altering partitions in existing partitioned tables.

How do I partition a MySQL database?

We can create a partition in MySQL using the CREATE TABLE or ALTER TABLE statement. Below is the syntax of creating partition using CREATE TABLE command: CREATE TABLE [IF NOT EXISTS] table_name. (column_definitions)

Does MySQL 5.7 support partition by?

MySQL 5.7 supports explicit selection of partitions and subpartitions that, when executing a statement, should be checked for rows matching a given WHERE condition.


1 Answers

There are a few solutions out there, if you want a total solution, check this post out on kickingtyres. It's a basic combination of a stored procedure handling the partition analysis and creation (with some logging!).

All you need to do is adjust it to your partition type (the example uses a bigint partition) and schedule the procedure to run with the MySQL Event Scheduler.

like image 145
Nick Craver Avatar answered Oct 01 '22 16:10

Nick Craver