리눅스에 MYSQL 설치하기
작성자 정보
- 관리자 작성
- 작성일
컨텐츠 정보
- 2,468 조회
- 0 추천
- 목록
본문
리눅스에 MYSQL 설치하기
지금까지는 리눅스기반의 웹서비스에 필요한 어플리케이션들과 각종 라이브러리들을 설치하였다.
이제 APACHE와 PHP, 그리고 MYSQL을 설치해야한다.
서두에서도 말했듯이 이 3가지는 리눅스기반에서 웹서비스를 위해 거의 대부분의 기업체나 개인등이 사용하는 것이다.
너무 잘 알려져있고 공인된 것이기 때문에 이 3가지의 궁합에 대한 설명은 더 이상 하지 않겠다.
하지만 설치하는 순서에 대해서는 알고있어야 한다.
이번 장에서 설명하고 있는 소프트웨어들의 설치순서대로 진행한다면 별 문제없이 무난히 설치할 수 있을 것이다.
그리고 APACHE와 PHP, 그리고 MYSQL은 반드시 다음과 같은 순서대로 설치하도록 하자.
① MYSQL ☞ ② APACHE ☞ ③ PHP ☞ ④ PHP ZendOptimizer
이와 같은 순서대로 설치할 것이며 설치하는 방법은 지금부터 필자와 함께 진행해 보도록 하자. 리눅스 자체의 설치도 마찬가지이지만 리눅스기반위에 이와 같이 설치되는 소프트웨어들의 설치방법도 설치후 시스템 성능에 큰 영향을 미치게 된다.
시스템관리의 효율성은 가장 최상의 설치에서부터 시작된다는 필자의 지론을 기억해주면 좋겠다.
자, 이제 MYSQL부터 설치를 시작해 보도록하자.
MYSQL의 전체적인 사용법과 활용법에 대하나 설명은 “MYSQL 데이터베이스” 강좌편에서 실무위주로 아주 자세히 다루고있다.
여기에서는 APM연동을 위한 MYSQL의 설치와 실행 및 MYSQL관리자 패스워드를 설정하는 방법등에 대해서 알아보도록 하겠다.
먼저, 다음과 같이 wget을 이용하여
MYSQL소스파일을 ftp.linux.co.kr에서 가져온다.
그리고 가져온 파일을 ls를 이용하여 확인하였다.
[root@sulinux local]#wget ftp://ftp.linux.co.kr/mysql/mysql-5.1.32.tar.gz --00:04:38-- ftp://ftp.linux.co.kr/mysql/mysql-5.1.32.tar.gz => `mysql-5.1.32.tar.gz' Resolving ftp.linux.co.kr... 210.127.253.100 Connecting to ftp.linux.co.kr|210.127.253.100|:21... connected. Logging in as anonymous ... Logged in! ==> SYST ... done. ==> PWD ... done. ==> TYPE I ... done. ==> CWD /mysql ... done. ==> SIZE mysql-5.1.32.tar.gz ... 30935032 ==> PASV ... done. ==> RETR mysql-5.1.32.tar.gz ... done. Length: 30935032 (30M)
100%[=======================================================================>] 30,935,032 1.43M/s in 22s
00:05:00 (1.35 MB/s) - `mysql-5.1.32.tar.gz' saved [30935032]
[root@sulinux local]# [root@sulinux local]#ls -l mysql-5.1.32.tar.gz -rw-r--r-- 1 root root 30935032 4월 15 00:05 mysql-5.1.32.tar.gz [root@sulinux local]# |
가져온 MYSQL압축소스파일을 압축해제하였다.
[root@sulinux local]#tar xvfz mysql-5.1.32.tar.gz mysql-5.1.32/ mysql-5.1.32/install-sh mysql-5.1.32/aclocal.m4 mysql-5.1.32/libmysql/ mysql-5.1.32/libmysql/dll.c mysql-5.1.32/libmysql/errmsg.c mysql-5.1.32/libmysql/client_settings.h mysql-5.1.32/libmysql/conf_to_src.c mysql-5.1.32/libmysql/libmysql.ver.in mysql-5.1.32/libmysql/password.c mysql-5.1.32/libmysql/CMakeLists.txt mysql-5.1.32/libmysql/get_password.c mysql-5.1.32/libmysql/libmysql.def mysql-5.1.32/libmysql/Makefile.shared … 이하생략 |
다음은 이렇게 생성된 디렉토리로 이동하여 configure를 실행하였다.
make로 컴파일을 수행하기 위해서는 필요한 Makefile파일을 생성하는 작업이다.
[root@sulinux local]#cd mysql-5.1.32 [root@sulinux mysql-5.1.32]# [root@sulinux mysql-5.1.32]#./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --enable-shared --enable-assembler --with-thread-safe-client --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static --with-mysqld-user="mysql" --with-readline --without-debug --without-docs --without-bench --with-charset=euckr configure: WARNING: unrecognized options: --with-thread-safe-client, --without-bench checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for a thread-safe mkdir -p... /bin/mkdir -p checking for gawk... gawk checking whether make sets $(MAKE)... yes checking "character sets"... default: euckr, collation: euckr_korean_ci; compiled in: euckr latin1 utf8 checking whether to compile national Unicode collations... yes … 중략 config.status: creating plugin/Makefile config.status: creating win/Makefile config.status: creating include/config.h config.status: executing depfiles commands config.status: executing default commands configure: WARNING: unrecognized options: --with-thread-safe-client, --without-bench
MySQL has a Web site at http://www.mysql.com/ 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 of the reference manual for hints about installing MySQL on your platform. Also have a look at the files in the Docs directory.
Thank you for choosing MySQL!
[root@sulinux mysql-5.1.32]# |
위의 복잡한 ./configure를 사용하는 대신 다음과 같이 필수 옵션들만 사용한 ./configure를 수행할 수도있다.
위의 예와 같은 방법을 사용하든 다음 필수옵션들만 사용한 방법을 사용하든 어떤 것을 사용해도 상관없지만 사용한 옵션들의 의미에 대해서는 알고있어야 한다.
MYSQL의 ./configure작업에서 사용하는 옵션들에 대한 설명은 밑에서 자세히 하고있다.
꼭 확인하기 바란다.
./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --enable-shared --with-mysqld-user="mysql" --with-charset=euckr
다음은 위에서 사용한 configure작업시에 사용할 수 있는 옵션들과 그 설명들이다.
필요한 소스를 직접 받아와서 설치할 때에는 이와 같은 옵션들의 사용에 능해야 한다.
즉 MYSQL 데이터베이스에 특별한 기능을 사용하거나 필요한 옵션들을 사용하기 위해서는 configure과정에서 이와 같은 옵션들을 사용하여 지정하면 된다.
--prefix=/usr/local/mysql
설치될 MYSQL의 위치이다.
즉 여기서 지정한 /usr/local/mysql디렉토리내에 MYSQL에 관한 모든 파일들과 디렉토리들이 생성된다.
--localstatedir=/usr/local/mysql/data
MYSQL의 데이터베이스 데이터들이
저장될 위치이다.
예를들어 bible이라는 데이터베이스를 생성하면 /usr/local/mysql/data/bible이라는 디렉토리내에 bible데이터베이스 파일들이 모두 저장된다.
그리고 여기서 지정한 /usr/local/mysql/data디렉토리는 MYSQL의 여러가지 로그파일들이 저장되는 위치이기도 한다.
설치 후에 이 디렉토리의 내용을 잘 살펴보기 바란다.
만약 MYSQL의 데이터베이스 데이터들이 저장될 위치를 다른곳으로 설정하려면 여기서 원하는 디렉토리를 절대경로로 지정하면 된다.
--with-charset=euckr
이 옵션은 MYSQL에서 한글지원을 하기위한 설정이다.
주의할 것은 예전버전에서는 euc_kr로 지정을 하였으나 4.1.X이후버전 부터는 euckr로 지정한다.
주의하기 바란다.
여기서 사용한 옵션외에도 다음과 같은 유용한 옵션이 있다.
참고로 “./configure --help”를 하면 모든 컴파일 옵션들을 확인할 수 있다.
--without-innodb
InnoDB테이블 핸들러를 포함하지
않고 컴파일한다.
--disable-largefile
큰파일 지원을 하지않도록 설치한다.
MYSQL데이터베이스의 성능보다는 안정성을 위한 옵션이다.
--with-raid
RAID를 지원하도록 컴파일한다.
--with-unix-socket-path=SOCKET
MYSQL소켓파일(mysql.sock)파일의 위치를 지정할 수 있다.
단, 지정하실 때에는 반드시 절대경로를 이용해야한다.
--with-mysqld-user=username
mysqld데몬을 실행할 계정명을 지정할 수 있다.
--with-zlib-dir=DIR
데이터압축 라이브러리인 zlib을 지원하기 위한 zlib설치위치를 지정하는 옵션이다.
--with-openssl-includes=DIR
OpenSSL을 지원하기위한 옵션으로 DIR에는 OpenSSL의 헤드위치를 지정한다.
--with-openssl-libs=DIR
OpenSSL의 라이브러리를 지원하기위한 옵션으로 DIR에는 OpenSSL의 라이브러리 위치를 지정한다.
--with-isam
ISAM타입의 테이블을 지원하는
옵션이다.
이외에도 유용한 옵션들이 많다.
자, 이제 컴파일을 하기 위하여 make를 실행한다.
[root@sulinux mysql-5.1.32]#make Making all in . make[1]: Entering directory `/usr/local/mysql-5.1.32' make abi_headers="include/mysql/plugin.h include/mysql.h" do_abi_check make[2]: Entering directory `/usr/local/mysql-5.1.32' set -ex; \ for file in include/mysql/plugin.h include/mysql.h; do \ gcc -E -nostdinc -dI \ -I./include \ -I./include/mysql \ -I./sql \ -I./include \ -I./include/mysql \ -I./sql \ $file 2>/dev/null | \ /bin/sed -e '/^# /d' \ -e '/^[ ]*$/d' \ -e '/^#pragma GCC set_debug_pwd/d' \ -e '/^#ident/d' > \ ./abi_check.out; \ /usr/bin/diff -w $file.pp ./abi_check.out; \ /bin/rm ./abi_check.out; \ done + for file in include/mysql/plugin.h include/mysql.h + gcc -E -nostdinc -dI -I./include -I./include/mysql -I./sql -I./include -I./include/mysql -I./sql include/mysql/plugin.h … 이하생략 |
그리고 “make install”을 실행한다.
“make install”을 실행하면 /usr/local/mysql 디렉토리내에 MYSQL데이터베이스 파일들을 모두 생성한다.
[root@sulinux mysql-5.1.32]#make install Making install in . make[1]: Entering directory `/usr/local/mysql-5.1.32' make abi_headers="include/mysql/plugin.h include/mysql.h" do_abi_check make[2]: Entering directory `/usr/local/mysql-5.1.32' … 중략 test -z "/usr/local/mysql/include/mysql" || /bin/mkdir -p "/usr/local/mysql/include/mysql" /usr/bin/install -c -m 644 'mysql.h' '/usr/local/mysql/include/mysql/mysql.h' /usr/bin/install -c -m 644 'mysql_com.h' '/usr/local/mysql/include/mysql/mysql_com.h' /usr/bin/install -c -m 644 'mysql_time.h' '/usr/local/mysql/include/mysql/mysql_time.h' /usr/bin/install -c -m 644 'my_list.h' '/usr/local/mysql/include/mysql/my_list.h' /usr/bin/install -c -m 644 'my_alloc.h' '/usr/local/mysql/include/mysql/my_alloc.h' /usr/bin/install -c -m 644 'typelib.h' '/usr/local/mysql/include/mysql/typelib.h' /usr/bin/install -c -m 644 'mysql/plugin.h' '/usr/local/mysql/include/mysql/plugin.h' /usr/bin/install -c -m 644 'my_dbug.h' '/usr/local/mysql/include/mysql/my_dbug.h' /usr/bin/install -c -m 644 'm_string.h' '/usr/local/mysql/include/mysql/m_string.h' /usr/bin/install -c -m 644 'my_sys.h' '/usr/local/mysql/include/mysql/my_sys.h' /usr/bin/install -c -m 644 'my_xml.h' '/usr/local/mysql/include/mysql/my_xml.h' … 중략 make[1]: Entering directory `/usr/local/mysql-5.1.32/win' make[2]: Entering directory `/usr/local/mysql-5.1.32/win' make[2]: Leaving directory `/usr/local/mysql-5.1.32/win' make[1]: Leaving directory `/usr/local/mysql-5.1.32/win' [root@sulinux mysql-5.1.32]# |
이제 /usr/local/mysql/bin로 이동하여 아래와 같이 “./mysql_install_db”를 실행한다.
“mysql_install_db를” 실행하면 MYSQL전체를 관리하기 위한 일명 “MYSQL 시스템테이블”들이 생성된다.
이 MYSQL시스템테이블들은 /usr/local/mysql/data 디렉토리내에 mysql 이라는 데이터베이스와 test라는 데이터베이스로 각각 생성된다.
여기서 test라는 것은 거의 이름만 있을 뿐이고 실제로 MYSQL시스템테이블들은 mysql이라는 데이터베이스내에 생성된다.
[root@sulinux mysql-5.1.32]#cd /usr/local/mysql/bin [root@sulinux bin]#./mysql_install_db 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/local/mysql/bin/mysqladmin -u root password 'new-password' /usr/local/mysql/bin/mysqladmin -u root -h sulinux.net password 'new-password'
Alternatively you can run: /usr/local/mysql/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/local/mysql ; /usr/local/mysql/bin/mysqld_safe &
You can test the MySQL daemon with mysql-test-run.pl cd /usr/local/mysql/mysql-test ; perl mysql-test-run.pl
Please report any problems with the /usr/local/mysql/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/ |
아래 예를보면 /usr/local/mysql디렉토리내에 data라는 디렉토리가 생성되었음을 알 수 있다.
방금 실행한 “./mysql_install_db”의 실행결과로 생성된 디렉토리이다.
[root@sulinux bin]#cd /usr/local/mysql/ [root@sulinux mysql]# [root@sulinux mysql]#ls -l 합계 36 drwxr-xr-x 2 root root 4096 4월 15 00:22 bin drwx------ 4 root root 4096 4월 15 00:33 data drwxr-xr-x 3 root root 4096 11월 27 2008 include drwxr-xr-x 3 root root 4096 11월 27 2008 lib drwxr-xr-x 2 root root 4096 4월 15 00:23 libexec drwxr-xr-x 4 root root 4096 11월 27 2008 man drwxr-xr-x 10 root root 4096 4월 15 00:23 mysql-test drwxr-xr-x 5 root root 4096 4월 15 00:23 share drwxr-xr-x 5 root root 4096 4월 15 00:23 sql-bench [root@sulinux mysql]# |
이제 MYSQL의 설치가 끝났다.
이제 MYSQL을 실행해 보도록하겠다.
MYSQL데몬인 mysqld를 실행하는 방법은 /usr/local/mysql/bin디렉토리내에 있는 mysqld_safe을 백그라운드로 실행하면 된다.
다음과 같이 실행해 보도록 하자.
[root@sulinux mysql]#chown -R mysql:mysql /usr/local/mysql/data [root@sulinux mysql]# [root@sulinux mysql]#/usr/local/mysql/bin/mysqld_safe & [1] 14285 [root@sulinux mysql]#110415 00:37:08 mysqld_safe Logging to '/usr/local/mysql/data/sulinux.net.err'. 110415 00:37:08 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
[root@sulinux mysql]# |
이제 정상적으로 실행이 되었으므로 실행된 mysqld데몬을 ps로 확인해 보았다.
모두 정상적으로 실행되어 있음을 확인할 수 있다.
[root@sulinux mysql]#ps -ef | grep mysqld root 14285 2482 0 00:37 pts/0 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe mysql 14375 14285 0 00:37 pts/0 00:00:00 /usr/local/mysql/libexec/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql --log-error=/usr/local/mysql/data/sulinux.net.err --pid-file=/usr/local/mysql/data/sulinux.net.pid --socket=/tmp/mysql.sock --port=3306 root 14379 2482 0 00:37 pts/0 00:00:00 grep --colour=auto mysqld [root@sulinux mysql]# |
이제 MYSQL의 모든 설치가 끝났다.
하지만 한가지가 남아있다.
다음과 같이 MYSQL의 관리자(root)패스워드를 설정해야 한다.
다음과 같이 /usr/local/mysql/bin디렉토리로 가서 mysqladmin이라는 실행문을 이용하여 MYSQL의 root사용자 패스워드를 설정한 것이다.
[root@sulinux mysql]#cd /usr/local/mysql/bin [root@sulinux bin]# [root@sulinux bin]#./mysqladmin -u root password 11111111 [root@sulinux bin]# |
이렇게 MYSQL의 root패스워드를 설정한 다음 MYSQL 데이터베이스에 접속하였다.
접속한 다음 “show databases”라는 SQL문을 간단히 사용해서 현재 시스템에 존재하는 데이터베이스리스트를 확인하였다.
그런다음 접속했던 MYSQL데이터베이스를 빠져나오기 위하여 exit를 실행하였다.
[root@sulinux bin]#./mysql -u root -p mysql Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.1.32 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> mysql> mysql> show databases;
+--------------------+ | Database | +--------------------+ | information_schema | | mysql | | test | +--------------------+ 3 rows in set (0.00 sec)
mysql> exit
Bye [root@sulinux bin]# |
이제 MYSQL의 설치와 설치후에 root사용자 패스워드 설정하는 방법에 대해서 모두 알아보았다.
거듭 말하지만 MYSQL데이터베이스를 운용하는 방법에 대해서는 MYSQL데이터베이스 강좌편을 보기 바란다.
아주 자세히 실무적인으로 설명해 두었으므로 실무능력향상에 큰 도움이 될 것이다.
관련자료
-
이전
-
다음