한글 인코딩에 관한 질문

litdream의 이미지

제로보드 4 로 운영되는 게시판을 제로보드 XE 로 교체하는 작업을 진행중입니다.
old db 에서 data 를 덤프 받아서, new db 에 옮겨야 하는데, 한글이 깨져서 나와서 도움을 요청합니다.

일단, 저의 UTF-8 인코딩 터미널에서는 첨부 이미지와 같이 보입니다.

우선 hexdump 바이트들과 실제 cat 되어 나온 문자들을 매치할수가 없어서 잘 맞지를 않습니다. ASCII 같기도 하고, ISO8859-1 같기도 하고...
EUC-KR 이 ISO-8859 식으로 표현되면 나타나는 형태같다고 해서, 역으로 iconv 를 적용해보기도 하였으나, illegal input sequence 에러가 나오는군요.

데이터베이스는 mysql 5 인데, 기본 인코딩으로 utf8 이지만, 테이블 인코딩은 latin1_swedish 입니다.
막상 web application 에서는 잘 표현이 되지만, export 받아서 해결보려는건 의도대로 안되네요.

처음에 어떻게 셋업이 되었는지는 잘 모르겠지만, 현재 상황에서 데이터를 빼오기가 쉽지않아서,
비슷한 경험 있으신분들 꼭좀 부탁드립니다.

File attachments: 
첨부파일 크기
Image icon data-conv.png20.86 KB
aero의 이미지

#!/usr/bin/env perl
use strict;
use warnings;
use Encode qw/decode encode/;
use utf8;
 
my $s1 = "게시";
my $s2 =  encode('utf8', encode('cp949', $s1));
print "$s2\n";
print unpack('H*', $s2), "\n";

결과

°Ô½Ã
c2b0c394c2bdc383

테스트코드로 해보니 utf8인코딩의 문자열을 cp949로 인코딩하고 다시 utf8로 인코딩해서 깨진 것 같네요

litdream의 이미지

답변 감사합니다.
어떻게 해서 저런 결과가 나왔는지도 몰랐는데, 원인을 찾아서 다행인데, 그다음 문제가 있습니다.
제가 가지고 있는 dmp 화일이 저 결과물인데, 저 결과물로 작업을 계속할수 있는가가 다음 문제군요.

utf8(A:database encoding) -> cp949(제로보드4 데이터) ---X---> utf8(B:dump file)

사실, 이번 기회에 그냥 UTF-8 로 변환해서 깔끔하게 정리하고 싶었는데, 어렴풋이 conversion 만으로 해결될줄 알았었습니다. 만약에 B 결과물로 작업이 안된다면, 무슨 방법이 있을까요? hosting company 에서는 web interface 만 제공해서, 거기서 dump 에게만 따로 encoding 을 적용할수 없는듯 보였습니다만, (phpMyAdmin 입니다.)

방법이 있을까요?

삽질의 대마왕...

litdream의 이미지

lookup table 을 만들어서 해결했습니다.
aero 님의 코드를 사용해서, 잘못 convert 된 utf-8 과 제대로된 utf-8 의 lookup table 을 만들어서, 그냥 변환했습니다.

문제는 한글만 변환되고, 다른 두 바이트 문자들은 예외처리를 했습니다.
이를테면, 2바이트 quote (', ") 는 일반 quote 로 바꾸었는데, 2바이트 ?, ! 도 있고, 예상치 못한 부호들도 있을듯 하네요.
혹시, cp949 의 모든 글자들을 모아놓은 테이블 어디 있는지 아시는분 계시나요?

일단 제가 작업한 분량만큼만이라도 올립니다.
필요하신분은 참고하시길..

삽질의 대마왕...

댓글 첨부 파일: 
첨부파일 크기
Plain text icon raw3.txt45.92 KB

삽질의 대마왕...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.