출처 : 한국리눅스유저그룹
원문 : MySQL 소스 인스톨 완전해부

MySQL 소스 인스톨 완전해부

MySQL 소스 인스톨  

[EUC_KR 정렬옵션 추가  및 한글 메시지 사용]

MySQL에서 한글 캐릭터 셋으로 정렬을 하기 위해서는 소스 컴파일을 해야 한다. 바이너리 배포판은 Latin1으로 설정되어 있어 한글로 정렬이 제대로 되지 않는다. 검색이 되지 않는 것은 아니다

컴파일 전에 반드시 확인해야 할 사항은  C 컴파일러의 버전이다 gcc 2.7.x 버전은 버그가 있으므로 MySQL을 설치하기 위해서는 꼭 2.8.x 버전으로 업그레이드하자.
레드햇 6.0  이상의 LINUX 라면 전혀 문제가 없다.

1) 설치준비

우선 http://www.mysql.org에서 최신 버전의 소스를 받아온다.
이 글을 쓰고 있는 현재 최신 버전은 3.23 베타 버전과 3.22.25 버전이다.
/tmp에 소스배포판이 있다고 가정하고 컴파일을 시작하자 먼저 압축을 푼다

압축풀기 : zcat mysql-version.tar.gz | tar xvf -
[root@localhost /tmp]# zcat mysql-3.22.23b.tar.gz | tar xvf -
                       mysql-3.22.23b/
                       mysql-3.22.23b/Makefile.in
                       mysql-3.22.23b/README
                       mysql-3.22.23b/stamp-h.in
                       mysql-3.22.23b/Makefile.am
                ...
                ...
                 ...
                mysql-3.22.23b/support-files/mysql.spec.sh
                mysql-3.22.23b/support-files/my-example.cnf.sh
                mysql-3.22.23b/support-files/mysql-log-rotate.sh
                mysql-3.22.23b/support-files/mysql.server.sh
                mysql-3.22.23b/support-files/binary-configure.sh

2) configure 스크립트 실행

압축이 풀린 디렉토리로 이동한후 cofigure 를 실행한다 사용가능한 옵션을 자세히 보려면 --help 를 붙여주면 된다.

[root@localhost /tmp]# cd mysql-3.22.23b
[root@localhost mysql-3.22.23b]# ./configure --help
            Usage: configure [options] [host]
            Options: [defaults in brackets after descript-xions]
            Configuration:
              --cache-file=FILE       cache             test results in FILE
              --help                              print this message
              --no-create                         do not create output files
              --quiet, --silent       do             not print `checking...' messages
              --version                           print the version of autoconf that created configure
              ...

다른 옵션은 모두 디폴트 값을 쓰고 --prefix=PREFIX 와  --with-charset=CHARSET 두가지만 설정을 하겠다.

--prefix : 컴파일이 끝난 후 파일들이 인스톨되는 디렉토리를 정해준다.
--with-charset  : 정렬에 사용될 캐릭터 셋을 정해 준다. 한글정렬을 위해 필요하다.
 
기본적으로 정해진 값은 latin1 이며 다음 값들 중 하나로 설정해 줄 수 있다.

 use specified charset (default is latin1, must be one of: big5 danish cp1251 cp1257 croat czech dec8 dos euc_kr german1 hebrew hp8 hungarian koi8_ru koi8_ukr latin1 latin2 swe7 usa7 win1251 win1251_ukr ujis sjis tis620)

그럼 두 가지 옵션을 주고 configure 스크립트를 실행하자. 설치될 디렉토리는 /usr/local/mysql 로 하고 euc_kr 정렬 옵션을 준다

                #./configure --prefix=/usr/local/mysql --with-charset=euc_kr

 loading cache ./config.cache
            checking host system type... i586-pc-linux-gnu
            checking target system type... i586-pc-linux-gnu
            checking build system type... i586-pc-linux-gnu
            checking for a BSD compatible install... (cached)
            ...
            ...
            ...
           
MySQL has a Web site at http://www.tcx.se/ which carries details on the latest release, upcoming
features, and other information to make your work or play with MySQL more productive. There you can
also find information about mailing lists for MySQL discussion.

Remember to check the platform specific part in the reference manual for hints about installing on your platfrom. See the Docs directory.
           
Thank you for choosing MySQL!

3) make


이제 본격적으로 컴파일할 준비가 끝났다. 마음을 가다듬고 컴파일을 시작하자

[root@localhost mysql-3.22.23b]# make
                          make  all-recursive
                   make[1]: Entering directory `/tmp/mysql-3.22.23b'
                   Making all in Docs
                   make[2]: Entering directory `/tmp/mysql-3.22.23b/Docs'
                   make[2]: Nothing to be done for `all'.
                   ...
                   ...
                   ...

컴파일 시간은 AMD K6-2 350MHz, 64M RAM을 가진 PC에서 5분 20초 정도 가 소요되었다. 참고로 예전에 3.21.20 버전을 486DX66 , RAM 16M의 리눅스 머신에서 컴파일 했을 때는 2 시간 30분 정도 걸렸던 기억이 난다. 만일 컴파일 중에 문제가 발생하면 INSTALL-SOURCE 파일을 참고한다. 여러 가지 상황별로 문제 해결 방법이 자세히 설명되어 있다.

4) make install

컴파일에 의해 만들어진 파일들을 인스톨하자

[root@localhost mysql-3.22.23b]# make install      
                   Making install in Docs
                   make[1]: Entering directory `/tmp/mysql-3.22.23b/Docs'
                   make[2]: Entering directory `/tmp/mysql-3.22.23b/Docs'
                   make[2]: Nothing to be done for `install-exec-am'.
                   /bin/sh ../mkinstalldirs /usr/local/mysql/info
                   mkdir /usr/local/mysql
                   ...
                   ...
                   ...
                   make[2]: Leaving directory `/tmp/mysql-3.22.23b'
                   make[1]: Leaving directory `/tmp/mysql-3.22.23b'
[root@localhost mysql-3.22.23b]#

5) 권한 테이블 초기화 :  mysql_install_db 실행

인스톨이 완료된 MySQL 디렉토리로 이동한다

[root@localhost mysql-3.22.23b]# cd /usr/local/mysql 

그 다음은 MySQL 데이터베이스의 각종 권한을 관리하는 데이터베이스 mysql에 테이블을 생성하는 스크립트를 실행해야 한다. 

/usr/local/mysql/bin에 있는 mysql_install_db 스크립트가 그 역할을 한다.

참고로 바이너리 베포판은 이 파일이 script-xs 디렉토리에 있다.

기본 테이블 생성 : ./bin/mysql_install_db
[root@localhost mysql]# ./bin/mysql_install_db
                 Creating db table
                 Creating host table
                 Creating user table
                 Creating func table
                 Creating tables_priv table
                 Creating columns_priv table

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 !
This is done with:
    /usr/local/mysql/bin/mysqladmin -u root password 'new-password'
See the manual for more instructions.
           
Please report any problems with the /usr/local/mysql/bin/mysqlbug script-x!

The latest information about MySQL is available on the web at http://www.mysql.com
            Support MySQL by buying support/licenses at http://www.tcx.se/license.htmy.
           
[root@localhost mysql]#
 
데이터 파일의 위치는 /usr/local/var 이며 데이터베이스는 디렉토리로 테이블은 파일로 존재한다. 참고로 바이너리 인스톨 시에는 데이터 디렉토리는  /usr/local/mysql/data 이다.

권한 테이블들이 만들어졌으면 먼저 MySQL root 유저의 패스워드를 변경해야 한다.
시스템의 root와는 전혀 상관이 없는 MySQL 의 기동, 권한관리, 데이터베이스 사용자 등록 등의 작업을 하는 사용자 이다.

MySQL root 암호 변경방법
/usr/local/mysql/bin/mysqladmin -u root password 'new-password'

위와 같은 방법으로 변경한다.

그러나 다음과 같은 에러가 발생할 것이다.
[root@localhost mysql]# /usr/local/mysql/bin/mysqladmin -u root password '1234'
 /usr/local/mysql/bin/mysqladmin: connect to server at 'localhost' failed
 error: 'Can't connect to local MySQL server through socket '/tmp/mysql.sock' (111)'
 Check that mysqld is running and that the socket: '/tmp/mysql.sock'  exists!
 [root@localhost mysql]#

원인은 MySQL 의 데이터베이스 서버 데몬이 동작하지 않기 때문이다.

6) MySQL 서버 데몬의 기동 : safe_mysqld

safe_mysqld 스크립트는 서버 데몬인 mysqld (MySQL 디렉토리의 libexec 에 있다) 를 시작하거나 비정상적으로 종료된 경우 재시작 한다.

먼저 데몬을 기동 시키자. 한글로 메시지를 보기 위해  옵션을 줄 수 있다.

# ./bin/safe_mysqld --language=korean &
     
=====
팁 : MySQL 의 각종 메시지를 한글로 보기를 원하면 --language=korean 옵션을 이용한다.
======

그리고 서버 데몬을 백그라운드로 동작시키기 위해 반드시 명령 뒤에 &를 붙여준다

[root@localhost mysql]# ./bin/safe_mysqld &                                               
                       [1] 24879

[root@localhost mysql]# Starting mysqld daemon with databases from  
                        /usr/local/mysql/var  <- enter 를 한번 쳐준다
[root@localhost mysql]#

프로세스를 확인해 보자

[root@localhost mysql]#  ps -ef | grep mysql
 root     24879   634  0 23:33             pts/1    00:00:00 sh ./bin/safe_mysqld
 root     24891 24879  0 23:33 pts/1                00:00:00 /usr/local/mysql/libexec/mysqld
 root     24893 24891  0 23:33 pts/1                00:00:00 /usr/local/mysql/libexec/mysqld
 root     24894 24893  0 23:33 pts/1                00:00:00 /usr/local/mysql/libexec/mysqld
 root     24909   634  0 23:41             pts/1    00:00:00 grep mysql
     
위와 같이 3개의 데몬이 떠 있으면 정상이다.

pstree 명령으로도 확인해 보자

[root@localhost mysql]#  pstree  
           
            init-+-atd
                 :
                 |-hanterm---bash-+-pstree
                 |                            `-safe_mysqld---mysqld---mysqld---mysqld
                 :


7) 관리자 암호 변경
이제 데몬이 기동 되었으니 다시 한번 암호변경을 시도해 본다.

[root@localhost mysql]# /usr/local/mysql/bin/mysqladmin -u root password '1234'
[root@localhost mysql]#
     
언제나 그렇듯이 무소식이 희소식이다.


8) 테스트

정상적으로 동작하는지 몇 가지 테스트를 해보자. 우선 mysql 이라는 클라이언트 프로그램을 이용해 권한관리 데이터베이스인 mysql에 접속해 보자

사용법 : ./bin/mysql [OPTIONS] [database]

더 많은 옵션을 알고 싶으면 ./bin/mysql --help 라고 입력하면 된다.

[root@localhost mysql]# ./bin/mysql mysql                               
ERROR 1045: 'root@localhost' 사용자는 접근이 거부 되었습니다. (Using password: 아니오)

접속이 거부되었다는 에러가 발생하였다. 당연하다 위에서 이미 MySQL 관리자 암호를 변경했기 때문에 암호를 이용해야 한다.

[root@localhost mysql]#  ./bin/mysql -p1234 mysql

위와 같이 passwd를 의미하는 -p 옵션 뒤에 공백 없이 암호를 입력하면 된다.

다음과 같이 -p옵션을 이용하고 나중에 암호를 입력하는 방식이 좀더 바람직하다.

[root@localhost mysql]# ./bin/mysql -p mysql   
Enter password:

암호가 맞는다면 다음과 같은 화면이 여러분을 반길 것이다.

  Reading table information for completion of table and column names
  You can turn off this feature to get a quicker startup with -A
  Welcome to the MySQL monitor.  Commands end with ; or g.
  Your MySQL connection id is 5 to server version: 3.22.23b

  Type 'help' for help.
         
  mysql>

           
몇 가지 명령을 각자 테스트  해 보자
           
mysql> status
      --------------
      ./bin/mysql  Ver 9.32 Distrib 3.22.23b, for pc-linux-gnu (i586)
Connection id:                      6
            Current database:       mysql
            Current user:                       root@localhost
            Server version                      3.22.23b
            Protocol version        10
            Connection                          Localhost via UNIX socket
            UNIX socket                         /tmp/mysql.sock
            Uptime:                             8 min 43 sec

Threads: 1  Questions: 37  Slow queries:             0  Opens: 10  Flush tables: 1  Open tables: 6
            --------------

mysql> select pi()*4/10 ;
            +------------+
            | pi()*4/10  |
            +------------+
            | 1.25663706 |
            +------------+
            1 row in set (0.00 sec)

mysql> select 'Hello World? I'm MySQL' AS string1;
            +------------------------+
            | string1                |
            +------------------------+
            | Hello World? I'm MySQL |
            +------------------------+
            1 row in set (0.00 sec)

           
mysql> select now() ;
            +---------------------+
            | now()               |
            +---------------------+
            | 1999-07-16 00:05:42 |
            +---------------------+
            1 row in set (0.00 sec)

           
mysql> use mysql
       Database changed
       mysql> desc user ;
       +-----------------+---------------+------+-----+---------+-------+
       | Field           | Type          | Null | Key | Default | Extra |
       +-----------------+---------------+------+-----+---------+-------+
       | Host            | char(60)      |      | PRI |         |       |
       | User            | char(16)      |      | PRI |         |       |
       | Password        | char(16)      |      |     |         |       |
       | Select_priv     | enum('N','Y') |      |     | N       |       |
       | Insert_priv     | enum('N','Y') |      |     | N       |       |
       | Update_priv     | enum('N','Y') |      |     | N       |       |
       | Delete_priv     | enum('N','Y') |      |     | N       |       |
       | Create_priv     | enum('N','Y') |      |     | N       |       |
       | Drop_priv       | enum('N','Y') |      |     | N       |       |
       | Reload_priv     | enum('N','Y') |      |     | N       |       |
       | Shutdown_priv   | enum('N','Y') |      |     | N       |       |
       | Process_priv    | enum('N','Y') |      |     | N       |       |
       | File_priv       | enum('N','Y') |      |     | N       |       |
       | Grant_priv      | enum('N','Y') |      |     | N       |       |
       | References_priv | enum('N','Y') |      |     | N       |       |
       | Index_priv      | enum('N','Y') |      |     | N       |       |
       | Alter_priv      | enum('N','Y') |      |     | N       |       |
       +-----------------+---------------+------+-----+---------+-------+
       17 rows in set (0.00 sec)

mysql> select Host, User ,Password , Select_priv, Insert_priv from user ;
     +-----------------------+------+------------------+-------------+-------------+
     | Host                  | User | Password         | Select_priv | Insert_priv |
     +-----------------------+------+------------------+-------------+-------------+
     | localhost             | root | 446a12100c856ce9 | Y           | Y           |
     | localhost.localdomain | root |                  | Y           | Y           |
     | localhost             |      |                  | N           | N           |
     | localhost.localdomain |      |                  | N           | N           |
     +-----------------------+------+------------------+-------------+-------------+
     4 rows in set (0.00 sec)

           
mysql> q
       Bye
[root@localhost mysql]#
     
9) MySQL 서버 중지
MySQL서버의 동작을 중지시키기 위해서는 다음의 명령을 사용한다.

==============================
서버 중지 :  ./bin/mysqladmin  shutdown
=============================
[root@localhost mysql]# ./bin/mysqladmin -p shutdown                    
                       Enter password:
[root@localhost mysql]# mysqld daemon ended

[1]+  Done
./bin/safe_mysqld --language=korean

[root@localhost mysql]# 
     
이상으로 소스배포본의 컴파일 작업은 모두 끝났다. 뒷부분에서 MySQL에  대해 더욱 자세히 다룰 것이다.


He can do, She can do, why not me?

+ Recent posts