사용자 도구

사이트 도구


wiki:mariadb:latin1에서_utf8mb4로_변환하기

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

양쪽 이전 판 이전 판
다음 판
이전 판
wiki:mariadb:latin1에서_utf8mb4로_변환하기 [2020/04/22 09:57]
hylee
wiki:mariadb:latin1에서_utf8mb4로_변환하기 [2023/01/13 18:44] (현재)
줄 1: 줄 1:
-====== latin1에서_utf8mb4로_변환하기 ======+====== latin1에서_utf8mb4로_변환하기 (Migration) ======
 <WRAP left notice 80%> <WRAP left notice 80%>
-  * description : Table Encoding 변환+  * description : Database Encoding Migration
   * author      : 도봉산핵주먹   * author      : 도봉산핵주먹
   * email       : hylee@repia.com   * email       : hylee@repia.com
줄 10: 줄 10:
 ===== 변환한 이유 ===== ===== 변환한 이유 =====
  
-> 내부 프로젝트 코** 본문태그 전체를 수집해서 DB에 Insert 할떄 생기는 에러 +에러내용 (내부 프로젝트 코** 본문태그 전체를 수집해서 DB에 Insert 할떄 생김) 
  
-  * ERROR 1366 (HY000) : incorrect string value : ''\xED\x95\x9C\xEC\x9A\xB0...' for column 'ARTCL_HTML' at row 1+  * ERROR 1366 (HY000) : incorrect string value : '\xED\x95\x9C\xEC\x9A\xB0...' for column 'ARTCL_HTML' at row 1
  
 > 분석 > 분석
줄 20: 줄 20:
  
 > 참고 > 참고
 +
   * mariaDB utf8은 3byte 이므로 이모티콘을 포함하려면 utf8mb4로 변환해야한다.   * mariaDB utf8은 3byte 이므로 이모티콘을 포함하려면 utf8mb4로 변환해야한다.
   * [[https://nuli.navercorp.com/sharing/blog/post/1079940|문자 집합(Character Set)과 인코딩(Encoding)]]   * [[https://nuli.navercorp.com/sharing/blog/post/1079940|문자 집합(Character Set)과 인코딩(Encoding)]]
  
 +===== 작업 순서 =====
 +  1. 현재 DB Character Set 을 확인한다. (utf8mb4인지 확인)
 +  2. DB를 dump 한다.
 +  3. mariaDB 설정파일에 인코딩 설정을 변경(, 추가) 한다.
 +  4. dump 파일에 DDL 설정이 utf8mb4인지 확인하고 아니면 utf8mb4로 수정한다.
 +  5. DB에 dump 파일로 data를 복구한다.
 +  6. mariaDB 재시작 후 DB 인코딩 확인한다.
 +  
 +==== 1. Character Set 확인 ====
 +> Table Caracter Set 확인
 +<code sql>
 +    SELECT CCSA.character_set_name FROM information_schema.`TABLES` T,
 +        information_schema.`COLLATION_CHARACTER_SET_APPLICABILITY` CCSA
 +    WHERE
 +        CCSA.collation_name = T.table_collation
 +    AND
 +        T.table_schema = "${Database name}"
 +    AND
 +        T.table_name = "${Table name}";
 +</code>
 +
 +  * [[https://www.lesstif.com/dbms/mysql-database-table-character-set-17105743.html|MySQL database 와 table 의 character set 확인하는 법]]
 +
 +
 +==== 2. Database dump ====
 +
 +
 +<code bash>
 + 
 +[root@mysql ~]# mysqldump -uroot -p ${Database Name} -r ${Backup File Name}.sql
 +Password:
  
 </code> </code>
-===== 중요 코드 ===== + 
-  list.get(list.size() - 1+==== 2-1. Dump File Encoding 확인 ==== 
-===== 결과 출력 ===== + 
-  The last element is D+  * file -bi를 하면 그 파일의 인코딩이 확인된다. 
 +  * Dump파일이 utf8 이여야지 DB를 utf9mb4로 변환했을때 깨짐없이 들어간다. 
 +<code bash> 
 + [root@mysql ~]# file -bi ${Backup File Name}.sql 
 +</code> 
 + 
 +==== 3. mariaDB 설정파일에 인코딩 설정 추가 ==== 
 +> 위치  
 +  * /etc/my.cnf 
 +> 추가 코드 
 +<code bash> 
 +
 +# This group is read both both by the client and the server 
 +# use it for options that affect everything 
 +
 +[client-server] 
 + 
 +
 +# include all files from the config directory 
 +
 +[mysqld] 
 +default_storage_engine=innodb 
 +innodb_buffer_pool_size=445M 
 +innodb_log_file_size=50M 
 +max_connections 10000 
 +connect_timeout = 600 
 +wait_timeout = 6000 
 +max_allowed_packet = 2G 
 +thread_cache_size = 128 
 +sort_buffer_size = 4M 
 +bulk_insert_buffer_size 16M 
 +tmp_table_size  = 32M 
 +max_heap_table_size = 32M 
 +default_storage_engine = InnoDB 
 +innodb_buffer_pool_size = 4G 
 +innodb_log_buffer_size  = 8M 
 +innodb_file_per_table   = 1 
 +innodb_file_format      = barracuda 
 +innodb_open_files       = 400 
 +innodb_io_capacity      = 400 
 +innodb_flush_method     = O_DIRECT 
 + 
 +character-set-server=utf8mb4 
 +collation-server=utf8mb4_general_ci 
 + 
 +[client] 
 +port=${Port} 
 +default-character-set = utf8mb4 
 + 
 +[mysqldump] 
 +default-character-set   = utf8mb4 
 + 
 +[mysql] 
 +default-character-set   = utf8mb4 
 + 
 +!includedir /etc/my.cnf.
 + 
 +</code> 
 +  
 + 
 +==== 4. dump 파일 DDL  ==== 
 +  * Dump 파일을 열어보면 DDL 코드가 있다. 
 +<code sql> 
 + 
 +DROP TABLE IF EXISTS `${Table name}`; 
 +/*!40101 SET @saved_cs_client     = @@character_set_client */; 
 +/*!40101 SET character_set_client = utf8 */; 
 +CREATE TABLE `${Table name}` ( 
 +  `${column}` ${type} NOT NULL, 
 +  `${column}` ${type} DEFAULT NULL, 
 +  `${column}` ${type} DEFAULT NULL, 
 +  `${column}` ${type} DEFAULT NULL, 
 +  `${column}` ${type} DEFAULT NULL, 
 +  PRIMARY KEY (${column}`) 
 +ENGINE=InnoDB DEFAULT CHARSET=utf8; 
 + 
 +</code> 
 +  * 위 DDL을 보면 마지막에 ''CHARSET=utf8;''가 있는데 이것을 ''CHARSET=utf8mb4;''로 수정해 준다. 
 + 
 +==== 5. DB에 dump 파일로 data를 복구한다. ==== 
 + 
 +  * [[https://niceman.tistory.com/60|[Database] MariaDB & MySQL - 데이터베이스 백업 및 복구 방법]] 
 ===== Ref ===== ===== Ref =====
-  * [[https://nuli.navercorp.com/sharing/blog/post/1079940|문자 집합(Character Set)과 인코딩(Encoding)]] + 
-{{tag>도봉산핵주먹 java List마지막요소}}+{{tag>도봉산핵주먹 mariadb CharacterSet Encoding utf8mb4 Migration}}
/volume1/web/dokuwiki/data/attic/wiki/mariadb/latin1에서_utf8mb4로_변환하기.1587517024.txt.gz · 마지막으로 수정됨: 2022/03/10 19:52 (바깥 편집)