Home > Database > Mysql Tutorial > How to Efficiently Change Database, Table, and Column Collations in MySQL?

How to Efficiently Change Database, Table, and Column Collations in MySQL?

Barbara Streisand
Release: 2024-12-02 13:47:09
Original
479 people have browsed it

How to Efficiently Change Database, Table, and Column Collations in MySQL?

How to Quickly Change Database, Table, and Column Collations

Changing the collation can be crucial to ensure proper data handling and storage. The question relates to altering the collation of an existing database, table, and column from latin1_general_ci to utf8mb4_general_ci using PhpMyAdmin.

Database Collation Alteration

To modify the default collation of a database, use the following command:

ALTER DATABASE <database_name> CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Copy after login

However, this only sets the new default for newly created tables.

Table Collation Alteration

To change the collation of a specific table, utilize the following command:

ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Copy after login

Column Collation Alteration

For modifying the collation of a single column, use the following command:

ALTER TABLE <table_name> MODIFY <column_name> VARCHAR(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
Copy after login

Note:

It's recommended to change the collation at the table level, as it automatically updates the collation of all columns within the table. Specific column alterations are only necessary in exceptional cases.

The above is the detailed content of How to Efficiently Change Database, Table, and Column Collations in MySQL?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template