• Save
Convert language latin1 to utf8 on mysql
Upcoming SlideShare
Loading in...5
×
 

Convert language latin1 to utf8 on mysql

on

  • 1,488 views

 

Statistics

Views

Total Views
1,488
Views on SlideShare
1,488
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft Word

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Convert language latin1 to utf8 on mysql Convert language latin1 to utf8 on mysql Document Transcript

  • 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;
  • 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)
  • (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.
  • (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.
  • (9) Now you can switch your application to new UTF-8 DB and check from theapplication.
  • 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)