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 database level, you can use the CREATE DATABASE
statement or ALTER DATABASE
statement (depending on whether you’re creating the database or modifying it).
Set the Character Set and Collation
To set the character set and collation when you first create a database, use the CHARACTER SET
and COLLATE
clauses of the CREATE DATABASE
statement:
CREATE DATABASE Solutions CHARACTER SET latin1 COLLATE latin1_german1_ci;
This example sets the character set to latin1
and the collation to latin1_german1_ci
.
Change the Character Set and Collation
To change the character set and collation of an existing database, use the CHARACTER SET
and COLLATE
clauses of the ALTER DATABASE
statement:
ALTER DATABASE Solutions CHARACTER SET hebrew COLLATE hebrew_general_ci;
This example changes the character set to hebrew
and the collation to hebrew_general_ci
.
Check the Character Set and Collation
In MySQL Workbench, you can check a database’s default collation by right-clicking the database and selecting Schema Inspector.
There are also several ways to check the collation using SQL.