Simplest Enterprise Continuous Integration Solutions

Saturday, March 31, 2012

MySQL: Convert MySQL DB characte set latin1 to utf8

Steps for converting JIRA MySQL DB character set latin1 to utf8:

JIRA's XML backup utility to backup JIRA database in XML format

Administration -> System -> Import & Export -> Backup System -> Backup JIRA data


# develop a Perl script (mysql_latin1_2_utf8.pl) to use ALTER TABLE/DATABASE SQL statements to convert data from latin1 to utf8

# automatically convert all text columns to utf8

ALTER TABLE <table_name> CONVERT TO CHARACTER SET utf8;

# for any future tables created in this database will use utf8 by default

ALTER DATABASE <database_name> CHARACTER SET utf8;

# mysql_latin1_2_utf8.pl usage

NAME
       mysql_latin1_2_utf8.pl
SYNOPSIS
       DESCRIPTION

       This script is going to convert MySQL database characte set from latin1 to utf8.
       VERSION
       Version 1.0
       USAGE
          perl mysql_latin1_2_utf8.pl --mysql_dbname "[mysql_dbname]" --mysql_username "[mysql_username]" --mysql_password "[mysql_password]" --mysql_host "[mysql_host]"
       ·   --mysql_dbname "[mysql_dbname]" - MySQL dbname. Required
       ·   --mysql_username "[mysql_username]" - MySQL username. Required
       ·   --mysql_password "[mysql_password]" - MySQL password. Option
       ·   --mysql_host "[mysql_host]" - MySQL host. Required
       EXAMPLE
          1. convert MySQL database characte set from latin1 to utf8.
          perl /tmp/mysql_latin1_2_utf8.pl --mysql_dbname "latin1jiradb" --mysql_username "root" --mysql_password "********" --mysql_host "linux64-jira-server"

# stop jira service

[root@linux64-jira-server ~]# service jira stop

# execute MySQL utf8 convertion

[root@linux64-jira-server ~]# perl /tmp/mysql_latin1_2_utf8.pl --mysql_dbname "latin1jiradb" --mysql_username "root" --mysql_password "********" --mysql_host "linux64-jira-server"

# restart mysql service

[root@linux64-jira-server ~]# service mysql restart

# start jira service

[root@linux64-jira-server ~]# service jira start

No comments:

Post a Comment