LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-20-2010, 02:09 AM   #1
windstory
Member
 
Registered: Nov 2008
Posts: 486

Rep: Reputation: 36
convert latin1 to utf8


convert latin1 to utf8

I have a problem at convert latin1 to utf8.

There are so many unreadable characters at latin1 db, and these characters could not convert into utf8 also. So I could not import to new utf8 db.

Is it possible to convert these character to utf8 to import to utf8 db?
 
Old 08-20-2010, 02:25 AM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,734

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
Hi,

You can use iconv to transform a sql file from one encoding to another.
First run "iconv -l" to see what character sets are supported and then use the one that matches you sql dump (usually ISO8859-1 is the same as LATIN1)
Code:
iconv -f ISO8859-1 -t UTF8 file.sql > file-utf8.sql
 
Old 08-20-2010, 03:44 AM   #3
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
bathory/

I have tried "iconv -f ISO8859-1 -t UTF8 my-dump.sql > mydump-utf8.sql", but when importing there is an error.

mysql -uroot -p my-db < mydump-utf8.sql

Quote:
,'http://www.google.co.kr/search?hl=ko&inlang=ko&ie=EUC-KR&newwindow=1&q=?깊????泥댁?ㅼ??? 湲곕??臾?,'Mozilla/4.0
 
Old 08-20-2010, 04:25 AM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,734

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
You might add the "--default-character-set=latin1" when you run mysqldump to dump your database and then run iconv (adding -c will omit invalid characters):
Code:
mysqldump -u root -p --mysqldump -u root -p my-db > my-dump.sql
iconv -c -f LATIN1 -t UTF8 my-dump.sql > mydump-utf8.sql
 
Old 08-20-2010, 08:44 AM   #5
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
bathory/

This is output of "mysqldump -u root -p --mysqldump -u root -p my-db > my-dump.sql".

mysqldump: unknown option '--mysqldump'

And "--default-character-set=latin1" after "iconv -c -f LATIN1 -t UTF8 my-dump.sql > mydump-utf8.sql" are also same result.
 
Old 08-20-2010, 08:52 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,734

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
Oups sorry, I guess I've somehow messed copy/paste. Anyway here it is:
Code:
mysqldump -u root -p --default-character-set=latin1 my-db > my-dump.sql
iconv -c -f LATIN1 -t UTF8 my-dump.sql > mydump-utf8.sql
 
Old 08-20-2010, 09:18 PM   #7
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by bathory View Post
Oups sorry, I guess I've somehow messed copy/paste. Anyway here it is:
Code:
mysqldump -u root -p --default-character-set=latin1 my-db > my-dump.sql
iconv -c -f LATIN1 -t UTF8 my-dump.sql > mydump-utf8.sql
Thanks, I tried yout codes but same result comes.
 
Old 08-21-2010, 08:33 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,734

Rep: Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584Reputation: 1584
Sorry to hear that. This iconv method was always working for me converting greek (iso8859-7) to utf8.
Anyway you might take a look at this (original here) to find other ways converting euc-kr to utf8

Regards
 
Old 08-21-2010, 07:32 PM   #9
windstory
Member
 
Registered: Nov 2008
Posts: 486

Original Poster
Rep: Reputation: 36
Quote:
Originally Posted by bathory View Post
Sorry to hear that. This iconv method was always working for me converting greek (iso8859-7) to utf8.
Anyway you might take a look at this (original here) to find other ways converting euc-kr to utf8

Regards
Thanks you for your kind further information.

I'll study and try.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How can I remove BOM if I am going convert UTF8 to ASCII mlibot Linux - Newbie 3 08-06-2009 08:21 PM
convert file from UTF8 to ASCII encoding graemef Programming 8 12-15-2008 04:45 AM
Mysql 4-5 migration as well as character set migration from latin1 to utf8? helptonewbie Linux - Server 3 05-15-2008 05:15 AM
convert sql file gb2312 -> utf8 secretlydead Linux - General 7 09-21-2007 09:46 AM


All times are GMT -5. The time now is 12:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration