Which MySQL Data Type to Use for Storing Boolean Values

Posted by Kyle Hankinson April 20, 2023


Short answer

MySQL has no separate boolean type. The MySQL reference manual lists BOOL and BOOLEAN under the numeric types and says: "These types are synonyms for TINYINT(1)." A value of zero is treated as false and any nonzero value as true. The keywords TRUE and FALSE are aliases for 1 and 0.

So these two columns are identical once created:

CREATE TABLE example (
    is_active BOOLEAN,
    is_admin  TINYINT(1)
);

SHOW CREATE TABLE example;
-- `is_active` tinyint(1) DEFAULT NULL,
-- `is_admin`  tinyint(1) DEFAULT NULL

Use BOOLEAN (or TINYINT(1)) for true/false columns. It takes 1 byte, it is what MySQL itself produces, and most drivers and ORMs map TINYINT(1) back to a boolean.

What "synonym for TINYINT(1)" means in practice

Because the column is really a TINYINT, MySQL does not stop you from storing other numbers in it:

INSERT INTO example (is_active) VALUES (TRUE), (FALSE), (5), (-1);

SELECT is_active FROM example;
-- 1, 0, 5, -1

All of those are valid: 5 and -1 count as true in a WHERE clause. That has two consequences:

  • WHERE is_active = TRUE only matches rows where the value is exactly 1, because TRUE is just 1. WHERE is_active (or WHERE is_active <> 0) matches every true value.
  • If you want the column to hold only 0 and 1, add a check constraint (enforced from MySQL 8.0.16):
ALTER TABLE example
    ADD CONSTRAINT chk_is_active CHECK (is_active IN (0, 1));

IS TRUE and IS FALSE also follow the zero/nonzero rule, so WHERE is_active IS TRUE matches 5 as well.

Does the (1) in TINYINT(1) matter?

The (1) is a display width, not a storage limit: a TINYINT(1) still holds -128 to 127. MySQL 8.0.17 deprecated display widths for integer types, with one exception: TINYINT(1) keeps showing its width, because many connectors (Connector/J, for example) use it to recognise a boolean column. That is why SHOW CREATE TABLE still prints tinyint(1) on MySQL 8.

The other options

Type Storage Good for Watch out for
BOOLEAN / TINYINT(1) 1 byte Almost every true/false column Accepts any value from -128 to 127 unless you add a check
BIT(1) 1 byte per column (bits are packed per row) Strict 0/1 values Client tools and drivers display it inconsistently (often as b'1' or a binary blob)
ENUM('no','yes') 1 byte Readable two-state values Sorting and comparisons follow the list order, and adding states needs ALTER TABLE
CHAR(1) with 'Y'/'N' 1 to 4 bytes (character set) Legacy schemas No built-in meaning; every query has to agree on the letters

SET sometimes appears in lists like this, but it stores a combination of several flags in one column (for example SET('read','write','delete')), so it is not a boolean.

Which to choose

  • A true/false column: BOOLEAN NOT NULL DEFAULT 0, plus a CHECK (col IN (0,1)) if other numbers must never get in.
  • A column that may later need a third state ("unknown", "pending"): a TINYINT with documented values, or an ENUM, rather than overloading NULL.
  • Moving data between databases: PostgreSQL has a true BOOLEAN, SQL Server uses BIT, and SQLite stores 0 and 1 in an integer column. TINYINT(1) in MySQL maps cleanly to all of them.

Tags: MySQL

About the author — Kyle Hankinson is the founder and sole developer of SQLPro Studio and the Hankinsoft Development suite of database tools. He has been building native macOS and iOS applications since 2010, and now ships SQLPro on Windows and Android as well.

Try SQLPro Studio — A powerful database manager for MySQL, PostgreSQL, Microsoft SQL Server, SQLite, Oracle, and Snowflake. Available on macOS, iOS, Android, and Windows.

Download Free Trial View Pricing Compare