Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Convert language latin1 to utf8 on mysql


Published on

Published in: Technology, Education
  • Be the first to comment

  • Be the first to like this

Convert language latin1 to utf8 on mysql

  1. 1. How to convert MySQL database from “Latin1” to “UTF8:Once client decided to switch database from Latin1 to UTF-8.Here I was working on a Linux platform at the time but you can do the same thingin Windows too.Character set and collation is possible to set at 4 levels on MySQL 5.0 version.I.eServer, Database, Table, Column. This means that you can have a table withcharacter set “Latin1”, and yet set one (Or more) of its columns to have differentcharacter sets like “UTF8”.You can use the following commands to see what character sets are in use in yourdatabase.For Database Level:SHOW VARIABLES LIKE „character_set_database‟;(OR) SHOW CREATE DATABASE db_name;For Table Level:SHOW CREATE table _name;
  2. 2. For COLUMN Level:SHOW CREATE table _name;Here are the steps for I followed to convert my Latin1 Database to a UTF8Database.(1) Create a new Database that has UTF8 specified as its default character set.Syntax:CREATE DATABASE new_dbname CHARACTER SET utf8COLLATE „utf8_general_ci ‟;(2) Export your database structure AND data by using mysqldump command.On Linux you can do like this...Syntax:mysqldump –uusername –ppassword latin1_db > /tmp/latindb.sqlHere Username and password are your MYSQL user name and password,latin1_db is the name of your existing database, and latindb.sql is the name youwant to give to the backup file.(3) Modify the SQL file you just finished exporting by opening it in any editor andreplace “CHARSET=latin1” with “CHARSET=utf8”.When you’re done withreplace, search for “latin1” to see if it shows up anywhere. You may find it incollate statements (e.g. COLLATE=latin1_swedish_ci).(4)If this is the case, you can either delete the collate statements, and let the tablesdefault to the collation set at the database level (or server level, if collation hasn’tbeen specified for the database)
  3. 3. (5) Replace the latin1 collation with the specific utf8 collation you want to use,save the file in ANSI format (encoding) with “Save as” and exit.Note: ANSI is a mother character set we can say as what we have basically justdone is make sure this file is encoded using Latin1 and all the characters used inthe SQL language have the same encoding in both Latin1 and UTF8.The SQLkeywords and syntax will be interpreted properly regardless of MYSQL thinks it islooking at Latin1 Or UTF8.
  4. 4. (6) Import the structure and data into your new UTF8 database which was createdin starting.On Linux, You can use following command likeMySQL –uusername –ppassword utf_db </tmp/latindb.sql(7) Now we just need to check data’s integrity to make sure that we are safe to goahead. You can also use some comparison tool for the same.(8)If everything looks good and worked, your data is now in UTF-8 format. Useany GUI tool for checking the data and I hope it will be in good shape.
  5. 5. (9) Now you can switch your application to new UTF-8 DB and check from theapplication.
  6. 6. Second way:1. Please make sure the database is created with character set utf8 and collationuntf8_unicode_ci.ssh live-arccms-01setSID live-arccms-01; getpass live-arccms-01mQcPGoxQ3BORA9mysql -udba_admin -pshow databases;use nickmom(database);[dba_admin@nickmom]> SHOW VARIABLES LIKE character_set_database;+------------------------+-------+| Variable_name | Value |+------------------------+-------+| character_set_database | utf8 |+------------------------+-------+1 row in set (0.00 sec)[dba_admin@nickmom]> SHOW VARIABLES LIKE collation_database;+--------------------+-----------------+| Variable_name | Value |+--------------------+-----------------+| collation_database | utf8_unicode_ci |+--------------------+-----------------+1 row in set (0.01 sec)