How to Set the Character Set and Collation of a Table in MySQL

In MySQL, you can specify the character set and collation at various levels. You can specify them at the connection level, the server level, the database level, the table level, and the column level. You can also specify a collation in your queries so that it overrides any collation that has been previously specified at the aforementioned levels.

To set the character set and collation at the table level, you can use the CREATE TABLE statement or ALTER TABLE statement (depending on whether you’re creating the table or modifying it).

Set the Character Set and Collation

To set the character set and collation when you first create a table, use the CHARACTER SET and COLLATE clauses within the CREATE TABLE statement:

CREATE TABLE Tasks (
    TaskId INT NOT NULL AUTO_INCREMENT,
    TaskName VARCHAR(255) NOT NULL,
    PRIMARY KEY (TaskId))
CHARACTER SET latin1 COLLATE latin1_general_ci;

This sets the table’s character set to latin1 and the collation to latin1_general_ci. This overrides the default collation set at the database and server levels.

Change the Character Set and Collation

To change the character set and collation of an existing table, use the CHARACTER SET and COLLATE clauses within the ALTER TABLE statement:

ALTER TABLE Tasks
CHARACTER SET tis620
COLLATE tis620_thai_ci;

This changes the table’s character set to tis620 and the collation to tis620_thai_ci.

Check the Character Set and Collation

In MySQL Workbench, you can check a table’s default collation by right-clicking the table and selecting Table Maintenance....

There are also several ways to check a table’s collation using SQL.