블로그 이미지
개발에 관한 것들.. 재만

카테고리

분류 전체보기 (66)
claztec's develop (1)
운영체제 (11)
프로그래밍 (41)
알고리즘 (0)
데이터베이스 (2)
소프트웨어공학 (3)
Books (2)
Total11,211
Today3
Yesterday9

'MySQL'에 해당되는 글 2건

  1. 2009/10/25 mysql 설치
  2. 2009/05/07 MySQL 한글 입력 문제 (1)
mysql 설치
http://dev.mysql.com/doc/refman/5.1/en/installing-binary.html

1. mysql 다운
wget 을 사용해서 다운.
커뮤니티서버 5.1 Linux (non RPM packages) downloads

mysql-5.1.41-linux-i686-glibc23.tar.gz



2. mysql 계정 만들기. - root를 안쓰고 mysql 이라는 계정으로 mysql을 관리한다.

mkdir /home/mysql
groupadd -g 300 mysql
useradd -u 300 -g 300 -d /home/mysql -s /bin/bash mysql
chown mysql:mysql /home/mysql

3. 다운받은 mysql 을 /user/local로 이동 후 chown을 통해 mysql:mysql로 변경.
이렇게 만들어 준다.
mysql@ubuntu:/usr/local$ ls -l
합계 36
drwxr-xr-x  2 root  root  4096 2009-10-10 15:20 bin
drwxr-xr-x  2 root  root  4096 2009-10-10 15:20 etc
drwxr-xr-x  2 root  root  4096 2009-10-10 15:20 games
drwxr-xr-x  2 root  root  4096 2009-10-10 15:20 include
drwxr-xr-x  3 root  root  4096 2009-10-10 15:20 lib
lrwxrwxrwx  1 root  root     9 2009-10-10 15:20 man -> share/man
lrwxrwxrwx  1 root  root    32 2009-10-25 10:47 mysql -> mysql-5.1.40-linux-i686-glibc23/
drwxr-xr-x 13 mysql mysql 4096 2009-10-07 05:28 mysql-5.1.40-linux-i686-glibc23
drwxr-xr-x  2 root  root  4096 2009-10-10 15:20 sbin
drwxr-xr-x  5 root  root  4096 2009-10-10 15:34 share
drwxr-xr-x  2 root  root  4096 2009-10-10 15:20 src
mysql@ubuntu:/usr/local$

4. configure
/usr/local/mysql/support-files/my-large.cnf 파일을 /etc/my.cnf 로 이름을 바꾸어서 복사해준다.
./scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql 실행 해준다.

mysql@ubuntu:/usr/local/mysql$ ./scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=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:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h ubuntu password 'new-password'

Alternatively you can run:
./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 . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/


5. mysql 띄우기
mysql 계정으로 사용자를 변경 한 후에 ./mysqld_safe --user=mysql & 이렇게 mysql을 띄운다.

mysql@ubuntu:/usr/local/mysql/bin$ ./mysqld_safe --user=mysql &
[1] 25969
mysql@ubuntu:/usr/local/mysql/bin$ 091025 10:59:20 mysqld_safe Logging to '/usr/local/mysql/data/ubuntu.err'.
091025 10:59:20 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

6. mysql 접속
mysql을 실행하면 끝..

7. 몇 몇 문제해결
mysql@claztec:/usr/local/mysql/bin$ ./mysqladmin stop
./mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/var/run/mysqld/mysqld.sock' exists!

mysqld.sock 없다고 에러가 나는데
/var/run 에 mysqld (mysql:mysql) 을 만들어주고
/etc/my.cnf 에서 mysqld.sock 경로를 다시 잡아주니 잘 되었다
#socket         = /tmp/mysqld.sock
socket          = /var/run/mysqld/mysqld.sock

--------------------------------------------

또 추가로 발생한 문제점.
 
부팅할때마다 /var/run/mysqld가 사라진다.
/var/run/mysqld를 /tmp로 심볼릭 링크해 주었다.


너무 대충 보고 정리해서 나중에 보면 뭔 말인지 모를수 있겠다.


저작자 표시 비영리 변경 금지
Posted by 재만
TAG MySQL
MySQL에 한글을 입력하면 ?? 로 표시되는 문제가 발생하였다.
결국 인코딩 문제 때문이었고, MySQL의 character를 변경해 주면 해결된다.

사용한 OS은 Ubuntu 9.04로 우분투는 기본적으로 시스템이 utf-8 을 갖는다.

MySQL설치는 시냅틱 패키지 관리자에서 MySQL server를 선택해서 설치하였다. 이렇게 설치하다보니 기본 언어설정을 못하고 지나치게 되었다. 그래서 characterset이 latin1으로 세팅이 되어 있었구 utf-8형태로 한글을 쓰다보니 한글이 깨져서 입력이 되었다.

1. characterset를 utf-8으로 변경
characterset을 바꾸기 위해서는 my.cnf 수정해야 한다. my.cnf 파일은 우분투에서 시냅틱 패키지 관리자로 설치하면 /etc/mysql 에 존재한다. my.cnf 수정은 http://ikinox.tistory.com/entry/mysql-%EB%8D%B0%EC%9D%B4%ED%84%B0%EB%B2%A0%EC%9D%B4%EC%8A%A4-%EC%84%A4%EC%B9%98utf-8-%EC%84%A4%EC%A0%95 에서 참조하였다.
참고로 설정파일도 함께 올렸다.

설정을 바꾸고 나서 MySQL을 재시작 해줘야 한다.
$sudo /etc/init.d/mysql restart

2. MySQL에 접속해서 characterset이 바뀌었는지 확인
설정이 적용이 되었다면 utf8로 변경이 된다. 내 경우에는 DB characterset은 latin1으로 계속해서 남아있었다. 그래도 결국 한글이 깨지진 않는다.

3. 테이블 생성
테이블을 생성해 줄때 character 설정을 utf8로 설정해 준다. 이부분이 가장 중요하다. 기존에 character 설정을 해주지 않고 테이블을 만들었다면 테이터가 한번 입력된 이후 테이블의 character 설정을 utf8로 변경을 해도 한글이 깨져서 입력될 가능성이 매우 높다. 이럴땐 과감히 drop 테이블을 하고 새롭게 만드는게 나은것 같다.
테이블을 만들때 MySQL Query Browser 와 같은 GUI 프로그램을 사용하면 편하게 설정해서 테이블을 만들 수 있다.



추가로 아래는 한글 입력이 깨지는 테이블과 깨지지 않는 테이블이다. MySQL Query Browser에서 Copy SQL to ClipBoard 을 통해 테이블을 create 한 쿼리를 보면 깨지는 테이블은 attribute에 character set이 latin1으로 되어 있는것을 확인할 수 있고 이때문에 한글이 입력되면 모두 latin1에 매칭되는 utf8 타입의 한글이 없어 ?로 입력되었던 것 같다.

<깨지는 테이블>
CREATE TABLE  `claztec`.`GUESTBOOK` (
  `guestbook_id` int(11) NOT NULL auto_increment,
  `register` datetime NOT NULL,
  `name` varchar(20) character set latin1 NOT NULL,
  `email` varchar(80) character set latin1 NOT NULL,
  `password` varchar(10) character set latin1 default NULL,
  `content` mediumtext character set latin1 NOT NULL,
  PRIMARY KEY  (`guestbook_id`)
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8

<깨지지 않는 테이블>
CREATE TABLE  `claztec`.`GUESTBOOK` (
  `guestbook_id` int(11) NOT NULL auto_increment,
  `register` datetime NOT NULL,
  `name` varchar(20) NOT NULL,
  `email` varchar(80) NOT NULL,
  `password` varchar(10) default NULL,
  `content` mediumtext NOT NULL,
  PRIMARY KEY  (`guestbook_id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8

4. 한글 입력
터미널에서 mysql을 실행해서 한글 입력테스트를 해본다. 이때 터미널 역시 인코딩이 UTF-8로 되어야 한다.


※ MEMBER 테이블에 깨진 문자가 입력된 이유는 my.cnf를 utf8로 변경하지 않고 insert를 해서 깨졌다.

5. 웹에서 입력
모든 character 설정 부분을 utf8로 한 후에 입력한다.
GUESTBOOK 테이블에 입력이 되는 프로그램이다. 최범균의 JSP 2.0 프로그래밍 방명록 예제 프로그램이다.

6. 데이터 베이스확인
실제 입력된 한글이 깨졌는지 확인한다.


할때 마다 생각하는 거지만 환경설정이 제일 힘들다. 환경설정에 기력을 쏟고 나면 정작 개발할 시간과 체력은 남지 않는것 같다.

끝으로 한글 인코딩에 관해서 참조한 글 http://cafe.naver.com/javacircle/34047
저작자 표시 비영리 변경 금지
Posted by 재만

최근에 달린 댓글

최근에 받은 트랙백

글 보관함