Schema and performance

Choose MySQL column types

Choose exact numeric, text, and time types while separating stored instants from local wall-clock dates and times.

8 minute lesson

~~~

Use integer types for whole numbers and DECIMAL for exact decimal values. For example, DECIMAL(5,2) stores an estimate such as 12.50 without binary floating-point rounding.

DATETIME stores the date and time you give it without time-zone conversion. It fits a local wall-clock value such as “2026-08-10 at 09:00 in the user’s chosen zone.” Store the zone separately.

TIMESTAMP converts between the session time zone and UTC. It fits created and updated instants when every connection uses a deliberate time-zone setting. In MySQL 8.4 it also has a smaller supported range than DATETIME.

Use VARCHAR for bounded text and TEXT for longer content. Pick types deliberately because changing a large table later can be expensive.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →