atlassian_confluence_jira

Some tables or columns in the database are not using utf8_bin for their collation, or the default collation for the database is incorrect.

Naan 2015. 11. 16. 11:52
반응형

Checks if the collation used by the tables, columns and database defaults in your MySQL database is correct.

Some tables or columns in the database are not using utf8_bin for their collation, or the default collation for the database is incorrect.


confluence나 jira 나 시스템 점검해주는 Tools 이 있다.

초기 DB 셋팅할때 제대로 했으면 모르겠지만 한참 운영중에 위와 같이 뜨면 문제가 발생할수 있다.

위 내용을 보면 utf8_bin 에러이다. DB를 확인하자

l> SELECT DEFAULT_CHARACTER_SET_NAME, DEFAULT_COLLATION_NAME FROM information_schema.SCHEMATA WHERE SCHEMA_NAME = 'dbname';

+----------------------------+------------------------+

| DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME |

+----------------------------+------------------------+

| utf8                       | utf8_general_ci        |

+----------------------------+------------------------+

1 row in set (0.00 sec)


처음 DB 생성일때 utf8_bin으로 해줬어야 하는데 제대로 생성이 안됐다.
db 생성할때 create database dbname character set utf8 만 입력해주면 default collation 값이 utf8_general_ci 로 된다.
저 DB때문에 에러가 발생한것이다.utf8_bin 으로 변경해주자

자 이제 변경을 하자.


우선 서버를 중단하자

그리고 mysql 접속
> select concat('alter table ',  table_name, ' convert to character set utf8 collate utf8_bin;') from information_schema.tables  where table_schema='dbname' and table_collation != 'utf8_bin' group by table_name;
입력을 하면 변경해야 할 리스트가 뜬다.
+--------------------------------------------------------------------------------------------+
| concat('alter table ',  table_name, ' convert to character set utf8 collate utf8_bin;')    |
+--------------------------------------------------------------------------------------------+
| alter table AO_187CCC_SIDEBAR_LINK convert to character set utf8 collate utf8_bin;         |
| alter table AO_21D670_WHITELIST_RULES convert to character set utf8 collate utf8_bin;      |
| alter table AO_26DB7F_ENTITIES_TO_ROOMS convert to character set utf8 collate utf8_bin;    |
| alter table AO_38321B_CUSTOM_CONTENT_LINK convert to character set utf8 collate utf8_bin;  |
| alter table AO_42E351_HEALTH_CHECK_ENTITY convert to character set utf8 collate utf8_bin;  |
| alter table AO_54C900_CONTENT_BLUEPRINT_AO convert to character set utf8 collate utf8_bin; |
| alter table AO_54C900_C_TEMPLATE_REF convert to character set utf8 collate utf8_bin;       |
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 블라 블라~
이렇게 뜨면 메모장 하나 열어서 복사를 하고 하나씩 붙여 넣으면 된다.

우선 변경전에
mysql> SET FOREIGN_KEY_CHECKS = 0;
만약에 위 명령어를 입력을 안한다면
mysql> alter table SPACES convert to character set utf8 collate utf8_bin;
ERROR 1025 (HY000): Error on rename of './confluence/#sql-3c4f_9c' to './confluence/SPACES' (errno: 150)
위와 같이 에러가 발생을 한다.

다 변경을했다면 다시 확인해보자 변경이 안된게 있는지

mysql> select concat('alter table ',  table_name, ' convert to character set utf8 collate utf8_bin;') from information_schema.tables  where table_schema='dbname' and table_collation != 'utf8_bin' group by table_name;
Empty set (0.00 sec)

empty set 으로 나오면 모두 변경된것이다.

mysql> ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_bin;

mysql> SET SESSION group_concat_max_len = 1000000;
SELECT GROUP_CONCAT(CONCAT('ALTER TABLE ', t.table_schema, '.', t.table_name, ' CONVERT TO CHARACTER SET utf8 COLLATE utf8_bin;') SEPARATOR '\n') as stmt
FROM information_schema.TABLES t, information_schema.COLLATION_CHARACTER_SET_APPLICABILITY c
WHERE c.collation_name = t.table_collation AND t.table_schema = 'dbname'
AND (c.character_set_name != 'utf8' OR c.collation_name != 'utf8_bin');

mysql> SET FOREIGN_KEY_CHECKS = 0;

하게 되면

에러가 사라진걸 확인 할수 있다.







반응형