How can I convert entire MySQL database character-set to UTF-8 and collation to UTF-8?
相关问题
- sqlyog export query result as csv
- NOT DISTINCT query in mySQL
- MySQL: conduct a basic search
- Why sometimes there is one of more gap(s) in the v
- mySQL alter table on update, current timestamp
Before proceeding, ensure that you: Have completed a full database backup!
Step 1: Database Level Changes
Identifying the Collation and Character set of your database
Fixing the collation for the database
Step 2: Table Level Changes
Identifying Database Tables with the incorrect character set or collation
Adjusting table columns' collation and character set
Capture upper sql output and run it. (like following)
refer to: https://confluence.atlassian.com/display/CONFKB/How+to+Fix+the+Collation+and+Character+Set+of+a+MySQL+Database
To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace DBNAME with the database name:
Use HeidiSQL. Its free and a very good db tool.
From tools menu, enter Bulk table editor
Select the complete database or pick tables to convert,
Execute
This converts complete database from latin to utf8 in just a few seconds.
Works like a charm :)
HeidiSQL connects by default as utf8 so any special characters should now be seen as the character (æ ø å) and not as encoded when inspecting the table data.
The real pitfall when moving from latin to utf8 is to make sure pdo connects with utf8 charset. If not you will get rubbish data inserted to the utf8 table and question marks all over the place on your web page, making you think the table data is not utf8...
Inspired by @sdfor comment, here is a bash script that does the job
alter table table_name charset = 'utf8';
This is a simple query i was able to use for my case, you can change the table_name as per your requirement(s).