TeamStation AI System Report LATAM IT Salaries 2024
Convert language latin1 to utf8 on mysql
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 thing
in Windows too.
Character set and collation is possible to set at 4 levels on MySQL 5.0 version.I.e
Server, Database, Table, Column. This means that you can have a table with
character set “Latin1”, and yet set one (Or more) of its columns to have different
character sets like “UTF8”.
You can use the following commands to see what character sets are in use in your
database.
For Database Level:
SHOW VARIABLES LIKE „character_set_database‟;
(OR) SHOW CREATE DATABASE db_name;
For Table Level:
SHOW CREATE table _name;
2. For COLUMN Level:
SHOW CREATE table _name;
Here are the steps for I followed to convert my Latin1 Database to a UTF8
Database.
(1) Create a new Database that has UTF8 specified as its default character set.
Syntax:CREATE DATABASE new_dbname CHARACTER SET utf8
COLLATE „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.sql
Here 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 you
want to give to the backup file.
(3) Modify the SQL file you just finished exporting by opening it in any editor and
replace “CHARSET=latin1” with “CHARSET=utf8”.When you’re done with
replace, search for “latin1” to see if it shows up anywhere. You may find it in
collate statements (e.g. COLLATE=latin1_swedish_ci).
(4)If this is the case, you can either delete the collate statements, and let the tables
default to the collation set at the database level (or server level, if collation hasn’t
been specified for the database)
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 just
done is make sure this file is encoded using Latin1 and all the characters used in
the SQL language have the same encoding in both Latin1 and UTF8.The SQL
keywords and syntax will be interpreted properly regardless of MYSQL thinks it is
looking at Latin1 Or UTF8.
4. (6) Import the structure and data into your new UTF8 database which was created
in starting.
On Linux, You can use following command like
MySQL –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 go
ahead. 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. Use
any GUI tool for checking the data and I hope it will be in good shape.
5. (9) Now you can switch your application to new UTF-8 DB and check from the
application.
6. Second way:
1. Please make sure the database is created with character set utf8 and collation
untf8_unicode_ci.
ssh live-arccms-01
setSID live-arccms-01; getpass live-arccms-01
mQcPGoxQ3BORA9
mysql -udba_admin -p
show 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)