MySQL : How to partition based on Month of date

MySQLmysql-5.6partitioning

I have a table having id as primary key and date column.

I want to partition the data.. I felt month would be the best option so that I have 12 partitions.. How do I achieve that !

I am using mysql 5.6 on AWS RDS.

alter table report.track_pdp_visit partition by hash(start_date);

It gives me following error:

Field 'start_date' is of a not allowed type for this type of
partitioning

Best Answer

From here, below is an example that range partitions by YEAR - change as appropriate.

Here is the part of the manual that explains how to alter tables and add partitions. You should be able to take it from here.

CREATE TABLE employees (
    id INT NOT NULL,
    fname VARCHAR(30),
    lname VARCHAR(30),
    hired DATE NOT NULL DEFAULT '1970-01-01',
    separated DATE NOT NULL DEFAULT '9999-12-31',
    job_code INT,
    store_id INT
)
PARTITION BY RANGE ( YEAR(separated) ) (
    PARTITION p0 VALUES LESS THAN (1991),
    PARTITION p1 VALUES LESS THAN (1996),
    PARTITION p2 VALUES LESS THAN (2001),
    PARTITION p3 VALUES LESS THAN MAXVALUE);