How to change collation of database, table, column | Alter charset and collation in all columns in all tables in MySQL | MySQL Collation - Setting Character Sets and Collations in MySQL.
Now the database is latin1_general_ci and I want to change collation to utf8_general_ci. Is there any setting in PhpMyAdmin to change collation of database, table, column? Rather than changing one by one?
(this will convert the columns just as well), or export the database with latin1 and import it back with utf8.
Changing it database wise:
ALTER DATABASE <database_name> CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Changing it per table:
ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8 COLLATE utf8_unicode_ci;
Good practice is to change it at table level as it'll change it for columns as well. Changing for specific column is for any specific case.
Changing collation for a specific column:
ALTER TABLE <table_name> MODIFY <column_name> VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci;
select CONCAT('alter table ',TABLE_SCHEMA,'.',TABLE_NAME, ' charset=utf8 COLLATE utf8_unicode_ci;')
from information_schema.TABLES WHERE TABLE_SCHEMA != 'information_schema' limit 100;
No comments:
Post a Comment