O'Reilly logo

MySQL 8 Cookbook by Karthik Appigatla

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

You can specify the partitioning while creating the table or by executing the ALTER TABLE command. The partition column should be part of all the unique keys in the table.

If you defined partitions based on the created_at column and id is the primary key, you should include the create_at column as part of PRIMARY KEY, that is, (id, created_at).

The following example assumes that there are no foreign keys referenced to the table.

If you wish to implement a partitioning scheme based on ranges or intervals of time in MySQL 8.0, you have two options:

  • Partition the table by RANGE, and for the partitioning expression, employ a function operating on a DATE, TIME, or DATETIME column and returning an integer value
  • Partition the table ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required