MySQL 설치 및 utf-8 인코딩 설정에 대하여 포스팅을 해보았습니다.
2014/12/15 - [개발에필요한연동법/리눅스서버구축] - CentOS 에서 MySQL 설치 및 UTF-8 설정하여 한글깨짐 현상 해결하기
윈도우는 보통 자동으로 대소문자 구분을 해주는 반면,
리눅스 환경(CentOS, Ubuntu 등..) 에서는 대소문자 구분이 되지 않을경우
별도로 설정을 추가해주어야 합니다.
예를 들어보고자 test DB의 테이블명 'test_table' 이라는 테이블을 생성 후
대소문자 설정을 해보도록 하겠습니다.
MySQL 접속 후 test DB내에 테이블 생성을 해보도록 하겠습니다.
[root@localhost local]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 4 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> create table test_table ( -> idx int, -> title varchar(50) -> ); Query OK, 0 rows affected (0.02 sec) mysql>
테이블 생성이 완료되었다면 테이블명을 대문자로 지정하여 SELECT 해보도록 하겠습니다.
mysql> SELECT * FROM TEST_TABLE; ERROR 1146 (42S02): Table 'test.TEST_TABLE' doesn't exist mysql>
test_table 테이블을 찾을수 없다는 에러메시지가 출력이 되는군요.
그렇다면 대소문자 구분에 대한 설정값이 어떻게 되어있는지 확인해보도록 하겠습니다.
mysql> show variables like 'lower_case_table_names'; +------------------------+-------+ | Variable_name | Value | +------------------------+-------+ | lower_case_table_names | 0 | +------------------------+-------+ 1 row in set (0.00 sec) mysql>
Value 값이 0일 경우 : 대소문자 구분(O)
Value 값이 1일 경우 : 대소문자 구분(X)
즉, Value값이 현재 0이므로 대소문자 구분을 하게 되있으므로
대문자로 테이블 조회시 존재하지 않는 테이블입니다라는 메시지가 출력된 것입니다.
그렇다면 대소문자 구분을 하지 않기 위해
Value값이 1로 변경을 해주기 위하여 다음 작업을 진행하도록 합니다.
이전 MySQL utf-8 인코딩 설정할때 수정해준 my.cnf 파일을 이용하여
대소문자 구분 설정을 해줘보도록 하겠습니다.
[root@localhost local]# vi /etc/my.cnf
[mysqld]하단에 다음 코드를 추가해주도록 합니다.
lower_case_table_names = 1
추가가 완료되었다면 mysql 데몬을 재시작하여
다시 한번 대문자로 test_table을 조회해보도록 하겠습니다.
[root@localhost local]# service mysqld restart mysqld 를 정지 중: [ OK ] mysqld (을)를 시작 중: [ OK ] [root@localhost local]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> use test Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed mysql> SELECT * FROM TEST_TABLE; Empty set (0.00 sec) mysql>
테스트 결과 정상적으로 대문자로 테이블 선언을 하였는데도
정상적으로 조회가 되는 것을 확인 할 수 있습니다.
by 개발로짜
가상머신에 설치된 CentOS에 SVN Server 구축 후 이클립스로 접속하기 (0) | 2014.12.20 |
---|---|
CentOS 몽고DB 다운로드 및 환경설정 후 접속테스트까지 간단하게 알아보기 (1) | 2014.12.19 |
CentOS 에서 MySQL 설치 및 UTF-8 설정하여 한글깨짐 현상 해결하기 (0) | 2014.12.15 |
CentOS tomcat-connector를 이용한 아파치 + 톰캣 간단 연동법 알아보기 (17) | 2014.12.11 |
CentOS wget을 이용하여 Apache 2.4 다운로드 및 서버 실행 (방화벽해제 포함) (1) | 2014.12.10 |
이번 CentOS 6.5에다가 MySQL설치를 간단하게 yum을 이용해보도록 하겠습니다.
MySQL 다운로드는 사이트 접속하여 로그인하고 여러개의 파일들을 다운로드 받아야해서 ;;;
제일먼저 mysql 인스톨을 합니다.
[root@localhost local]# yum -y install mysql*
설치가 완료되었다면 MySQL 데몬을 실행을 해보도록 하겠습니다.
[root@localhost local]# service mysqld start MySQL 데이타베이스 초기화 중: Installing MySQL system tables... OK Filling help tables... OK To start mysqld at boot time you have to copy support-files/mysql.server to the right place for your system PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER ! To do so, start the server, then issue the following commands: /usr/bin/mysqladmin -u root password 'new-password' /usr/bin/mysqladmin -u root -h localhost.localdomain password 'new-password' Alternatively you can run: /usr/bin/mysql_secure_installation which will also give you the option of removing the test databases and anonymous user created by default. This is strongly recommended for production servers. See the manual for more instructions. You can start the MySQL daemon with: cd /usr ; /usr/bin/mysqld_safe & You can test the MySQL daemon with mysql-test-run.pl cd /usr/mysql-test ; perl mysql-test-run.pl Please report any problems with the /usr/bin/mysqlbug script! [ OK ] mysqld (을)를 시작 중: [ OK ]
정상적으로 데몬이 실행이 되었다면
MySQL 접속테스트를 진행해보겠습니다.
※ 초기 root계정의 패스워드는 없으므로 Enter password부분은 그냥 Enter키를 눌러서 넘겨주도록 합니다.
[root@localhost local]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql>
이제는 MySQL의 인코딩 타입을 확인해보도록 합니다.
mysql> show variables like 'c%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | latin1 | | character_set_connection | latin1 | | character_set_database | latin1 | | character_set_filesystem | binary | | character_set_results | latin1 | | character_set_server | latin1 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | | collation_connection | latin1_swedish_ci | | collation_database | latin1_swedish_ci | | collation_server | latin1_swedish_ci | | completion_type | 0 | | concurrent_insert | 1 | | connect_timeout | 10 | +--------------------------+----------------------------+ 14 rows in set (0.00 sec) mysql>
인코딩 확인 결과 대부분의 character_set이 latin1로 설정이 되어있습니다.
이럴경우 한글깨짐 현상이 발생할 확률이 크므로
latin1인코딩 타입을 utf8 타입으로 변경해주도록 하겠습니다.
리눅스 환경일 경우 my.cnf 파일을 수정해주시면 되겠고
윈도우 환경은 my.ini 파일을 수정해주시면 되겠습니다.
저는 리눅스 환경이므로 my.cnf 파일을 수정해보도록 하겠습니다.
[root@localhost local]# vi /etc/my.cnf
하단 각 [xxxx] 선언이 되있는 하단에 각 인코딩 설정코드들을 추가해주도록 합니다.
[xxxx] 자체가 없다면 [xxxx] 부분도 같이 추가해주도록 합니다. ^^
[client] #추가 default-character-set = utf8 [mysqld] #추가 init_connect="SET collation_connection = utf8_general_ci" init_connect="SET NAMES utf8" default-character-set = utf8 character-set-server = utf8 collation-server = utf8_general_ci [mysqldump] #추가 default-character-set = utf8 [mysql] #추가 default-character-set = utf8
위 인코딩 설정을 모두 잡아주었다면 데몬을 재시작 후
다시 한번 인코딩타입을 재확인해보도록 하겠습니다.
[root@localhost local]# service mysqld restart mysqld 를 정지 중: [ OK ] mysqld (을)를 시작 중: [ OK ] [root@localhost local]#
[root@localhost local]# mysql -uroot -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like 'c%'; +--------------------------+----------------------------+ | Variable_name | Value | +--------------------------+----------------------------+ | character_set_client | utf8 | | character_set_connection | utf8 | | character_set_database | utf8 | | character_set_filesystem | binary | | character_set_results | utf8 | | character_set_server | utf8 | | character_set_system | utf8 | | character_sets_dir | /usr/share/mysql/charsets/ | | collation_connection | utf8_general_ci | | collation_database | utf8_general_ci | | collation_server | utf8_general_ci | | completion_type | 0 | | concurrent_insert | 1 | | connect_timeout | 10 | +--------------------------+----------------------------+ 14 rows in set (0.00 sec) mysql>
위처럼 설정 후 MySQL의 인코딩타입을 확인해 본 결과
모든 인코딩이 utf8 환경으로 변경 된 것을 확인 할 수 있었습니다.
MySQL 한글 깨짐현상 문제에 대하여 해결이 되시길... ^^
by 개발로짜
CentOS 몽고DB 다운로드 및 환경설정 후 접속테스트까지 간단하게 알아보기 (1) | 2014.12.19 |
---|---|
리눅스환경에서 MySQL 대소문자 구분을 하지 않기위한 설정방법 알아보기 (0) | 2014.12.15 |
CentOS tomcat-connector를 이용한 아파치 + 톰캣 간단 연동법 알아보기 (17) | 2014.12.11 |
CentOS wget을 이용하여 Apache 2.4 다운로드 및 서버 실행 (방화벽해제 포함) (1) | 2014.12.10 |
CentOS 6.5 - Tomcat7 다운로드 + 서버 실행 및 방화벽 해제 알아보기 (0) | 2014.12.09 |
아파치에서 제공하는 "tomcat-connector" 를 이용하면
아파치와 톰캣을 연결하여 아파치 포트(80)로 접속하게 되면
톰캣 웹화면이 출력되게끔 해주는 커넥터입니다.
물론, 톰캣 포트를 그냥 8080을 80으로 변경해서 접속해도 가능하나
보안이 문제가 된다고 합니다.
해당 포스팅에는 톰캣을 80으로 적용시 발생되는 문제점은 다루지 않도록 하겠습니다.
그럼 이전 포스팅에 이어서 apache + tomcat 연동법을 공유하도록 하겠습니다.
2014/12/09 - [개발에필요한연동법/리눅스서버구축] - CentOS 6.5 - Tomcat7 다운로드 + 서버 실행 및 방화벽 해제 알아보기
2014/12/10 - [개발에필요한연동법/리눅스서버구축] - CentOS wget을 이용하여 Apache 2.4 다운로드 및 서버 실행 (방화벽해제 포함)
아파치와 톰캣이 설치되어있다는 가정하에 진행하도록 하겠습니다.
tomcat-connector파일을 wget명령어를 이용하여 다운로드 받도록 하겠습니다.
[root@localhost local]# cd /usr/local [root@localhost local]# wget http://apache.mirror.cdnetworks.com/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.40-src.tar.gz -O connector.tar.gz --2014-12-10 10:57:29-- http://apache.mirror.cdnetworks.com/tomcat/tomcat-connectors/jk/tomcat-connectors-1.2.40-src.tar.gz Resolving apache.mirror.cdnetworks.com... 61.110.198.174 Connecting to apache.mirror.cdnetworks.com|61.110.198.174|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1526449 (1.5M) [application/x-gzip] Saving to: `connector.tar.gz' 100%[======================================>] 1,526,449 4.39M/s in 0.3s 2014-12-10 10:57:49 (4.39 MB/s) - `connector.tar.gz' saved [1526449/1526449]
다운로드가 완료되었나요?
그럼 압축 해제를 한다음
컴파일 + 인스톨진행 하도록 하겠습니다.
[root@localhost local]# tar -zxvf connector.tar.gz [root@localhost local]# cd tomcat-connectors-1.2.40-src/native/ [root@localhost native]# ./configure --with-apxs=/usr/local/apache/bin/apxs [root@localhost native]# make && make install
커넥터 설치가 완료되었다면 아파치 디렉토리내에 있는 "conf" 디렉토리로 이동합니다.
[root@localhost native]# cd /usr/local/apache/conf/
아파치와 톰캣을 연결해주는 중요 설정부분이므로
각 순서별로 진행하시면 되겠습니다.
[root@localhost conf]# vi workers.properties
workers.tomcat_home="/usr/local/apache-tomcat-7.0.57" workers.java_home="/usr/java/jdk1.7.0_72" ps=/ worker.list=ajp13 worker.ajp13.port=8009 worker.ajp13.host=localhost worker.ajp13.type=ajp13
workers.tomcat_home에 대입되는 경로는
톰캣디렉토리경로를 작성해주면 되겠습니다.
workers.java_home에는 JDK의 디렉토리 설치경로를
작성해주시면 되겠고요.
[root@localhost conf]# vi mod_jk.conf
<IfModule mod_jk.c> JkWorkersFile "/usr/local/apache/conf/workers.properties" JkLogFile "/usr/local/apache-tomcat-7.0.57/logs/mod_jk.log" JkLogLevel info JkAutoAlias "/usr/local/apache-tomcat-7.0.57/webapps" JkMount /* ajp13 JkMount /*.jsp ajp13 JkMount /servlet/* ajp13 JkMount /examples/*.jsp ajp13 JkLogStampFormat "[%a %b %d %H:%M:%S %Y]" JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories JkRequestLogFormat "%w %V %T" </IfModule>
JkWorkersFile에는 workers.properties 파일경로를 작성해줍니다.
JkLogFile의 경우는 톰캣의 로그디렉토리에
"mod_jk.log" 파일명을 선언해줍니다
( mod_jk.log 에 대한 파일명은 필수는 아닐거같군요.)
이어서 conf디렉토리내에 존재하는 httpd.conf파일에
해당 코드들을 추가해주도록 합니다.
[root@localhost conf]# vi httpd.conf
vi 실행 후 하단으로 좀 내리다보면
LoadModule이라고 여러개 선언되어있는 부분이 있는데
이 부분에 맨 끝라인 다음줄에 다음 코드를 추가해주도록 합니다.
LoadModule jk_module modules/mod_jk.so
httpd.conf 파일 맨 끝으로 내린 후,
코드를 추가해주도록 합니다.
include conf/mod_jk.conf
지금까지 했던 부분이 아파치와 톰캣 연동에 마지막 절차입니다.
자 그럼 아파치와 톰캣서버를 각각 실행시켜주도록 해보겠습니다.
[root@localhost local]# cd /usr/local/apache-tomcat-7.0.57/bin/ [root@localhost bin]# ./startup.sh
[root@localhost bin]# cd /usr/local/apache/bin/ [root@localhost bin]# ./apachectl start
기존 80포트 접속시 "it works!" 라는 문구가 출력이 되었으나
톰캣커넥터 연동으로 인하여 하단과 동일한 실행화면이 출력될 것입니다.
by 개발로짜
리눅스환경에서 MySQL 대소문자 구분을 하지 않기위한 설정방법 알아보기 (0) | 2014.12.15 |
---|---|
CentOS 에서 MySQL 설치 및 UTF-8 설정하여 한글깨짐 현상 해결하기 (0) | 2014.12.15 |
CentOS wget을 이용하여 Apache 2.4 다운로드 및 서버 실행 (방화벽해제 포함) (1) | 2014.12.10 |
CentOS 6.5 - Tomcat7 다운로드 + 서버 실행 및 방화벽 해제 알아보기 (0) | 2014.12.09 |
CentOS에 wget을 이용하여 JDK1.7 RPM 다운로드 후 설치하기 (0) | 2014.12.09 |