캠핑과 개발


다운 : http://www.mysql.com/downloads/mysql/5.1.html#downloads

Compressed TAR Archive 다운

1. mysql 사용자 등록
설치를 하기전에 mysql 을 실행할때 (./mysql_safe &)  mysqld 데몬을 실행할 mysql 이라는 사용자를 생성하여야 한다.

[root@localhost bin]# groupadd mysql
[root@localhost bin]# useradd -g mysql mysql -M

순서는 group 먼저 생성후 user 생성...
-M 옵션은 사용자 홈디렉토리를 만들지 않겠다는것


2. configure
[root@localhost mysql-5.1.57]# ./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --enable-shared --with-mysqld-user="mysql" --with-charset=utf8
.
.
.
.
Thank you for choosing MySQL!

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.

[root@localhost mysql-5.1.57]#
./configure 시 옵션에대하여 살펴 보면...

--prefix=/usr/local/mysql
설치될 경로

--localstatedir=/usr/local/mysql/data
 mysql의 DB data 저장될 위치를 지정, 디폴트 설정은 /usr/local/var

--enable-shared
shared 옵션을 사용하는 것으로 지정.

--with-mysqld-user="mysql"
mysql을 실행할 계정명 지정. mysql로 지정함.

--with-charset=euckr
한글을 지원하기 위한 문자셋을 지정함.

--with-raid
raid를 지원하게 컴파일 함.

--with-openssl-includes= openssl_헤드위치지정     
openssl을 지원하기 위한 옵션 지정

--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock
소켓관련 패스 재설정

--with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
컴파일 옵션으로 'CXX=gcc'를 사용할 때 오류를 피하기 위해 공유 라이브러리를 사용하지 않음


CC=gcc CXX=gcc ./configure
'libg++' or `libstdc++' 없이 gcc만으로 컴파일을 한다.


이외에도 더 많은 옵션이 있다...

--prefix=/usr/local/mysql
--localstatedir=/usr/local/mysql/data
--enable-shared
--with-mysqld-user="mysql"
--with-charset=utf8

이정도만 지정해도 기본적으로 사용이 가능한 모양임...

3. make를 통한 컴파일

[root@localhost mysql-5.1.57]# make

컴파일러 (여기에서는 gcc) 가 설치 되어있지 않으면 당연하게도 컴파일이 안된다.
컴파일러가 설치 되어있는지 확인하고 make 해준다.


4. make install로 컴파일된 바이너리 파일을 설치/복사 하여준다.
[root@localhost mysql-5.1.57]# make install

configure -> make -> make install 을 통해서 mysql 의 설치가 되었다.


5. mysql을 관리하는 mysql system table 생성
configure 에서 --localstatedir=/usr/local/mysql/data  라고 경로를 지정했으므로 요 위치에  mysql 과 test 라는 db가 생성된다.
[root@localhost bin]# pwd
/usr/local/mysql/bin
[root@localhost bin]# ls -al
합계 16516
drwxr-xr-x  2 root root    4096 2011-05-10 16:10 .
drwxr-xr-x 10 root root    4096 2011-05-10 16:11 ..
-rwxr-xr-x  1 root root   24544 2011-05-10 16:10 innochecksum
-rwxr-xr-x  1 root root    1424 2011-05-10 16:10 msql2mysql
-rwxr-xr-x  1 root root  791599 2011-05-10 16:10 my_print_defaults
-rwxr-xr-x  1 root root 2151481 2011-05-10 16:10 myisam_ftdump
-rwxr-xr-x  1 root root 2507505 2011-05-10 16:10 myisamchk
-rwxr-xr-x  1 root root 2188320 2011-05-10 16:10 myisamlog
-rwxr-xr-x  1 root root 2242622 2011-05-10 16:10 myisampack
-rwxr-xr-x  1 root root  637894 2011-05-10 16:10 mysql
-rwxr-xr-x  1 root root  793479 2011-05-10 16:10 mysql_client_test
-rwxr-xr-x  1 root root    6141 2011-05-10 16:10 mysql_config
-rwxr-xr-x  1 root root    4169 2011-05-10 16:10 mysql_convert_table_format
-rwxr-xr-x  1 root root    3245 2011-05-10 16:10 mysql_find_rows
-rwxr-xr-x  1 root root    1226 2011-05-10 16:10 mysql_fix_extensions
-rwxr-xr-x  1 root root    5894 2011-05-10 16:10 mysql_fix_privilege_tables
-rwxr-xr-x  1 root root   14362 2011-05-10 16:10 mysql_install_db
-rwxr-xr-x  1 root root    8033 2011-05-10 16:10 mysql_secure_installation
-rwxr-xr-x  1 root root   17438 2011-05-10 16:10 mysql_setpermission
-rwxr-xr-x  1 root root  688935 2011-05-10 16:10 mysql_tzinfo_to_sql
-rwxr-xr-x  1 root root   87453 2011-05-10 16:10 mysql_upgrade
-rwxr-xr-x  1 root root  392162 2011-05-10 16:10 mysql_waitpid
-rwxr-xr-x  1 root root    3818 2011-05-10 16:10 mysql_zap
-rwxr-xr-x  1 root root  111597 2011-05-10 16:10 mysqlaccess
-rwxr-xr-x  1 root root   39569 2011-05-10 16:10 mysqladmin
-rwxr-xr-x  1 root root  223719 2011-05-10 16:10 mysqlbinlog
-rwxr-xr-x  1 root root   10645 2011-05-10 16:10 mysqlbug
-rwxr-xr-x  1 root root   68840 2011-05-10 16:10 mysqlcheck
-rwxr-xr-x  1 root root   24162 2011-05-10 16:10 mysqld_multi
-rwxr-xr-x  1 root root   16772 2011-05-10 16:10 mysqld_safe
-rwxr-xr-x  1 root root  184007 2011-05-10 16:10 mysqldump
-rwxr-xr-x  1 root root    7351 2011-05-10 16:10 mysqldumpslow
-rwxr-xr-x  1 root root   32463 2011-05-10 16:10 mysqlhotcopy
-rwxr-xr-x  1 root root   61125 2011-05-10 16:10 mysqlimport
-rwxr-xr-x  1 root root   70042 2011-05-10 16:10 mysqlshow
-rwxr-xr-x  1 root root   98506 2011-05-10 16:10 mysqlslap
-rwxr-xr-x  1 root root  338120 2011-05-10 16:10 mysqltest
-rwxr-xr-x  1 root root  737505 2011-05-10 16:10 perror
-rwxr-xr-x  1 root root  756375 2011-05-10 16:10 replace
-rwxr-xr-x  1 root root  744052 2011-05-10 16:10 resolve_stack_dump
-rwxr-xr-x  1 root root  729755 2011-05-10 16:10 resolveip
[root@localhost bin]#

[root@localhost 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 localhost.localdomain 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!

[root@localhost bin]#


6. msyql 실행
[root@localhost bin]# ./mysqld_safe &
[1] 11878
[root@localhost bin]# 110510 19:48:18 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
110510 19:48:18 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
110510 19:48:18 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended

[1]+  Done                    ./mysqld_safe
[root@localhost bin]#

마지막줄  mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended 에 주목!!

요메시지가 나오면 정상이 아닌거다!!!!

로그를 보면....

[root@localhost bin]# cd /usr/local/mysql/data/
[root@localhost data]# cat localhost.localdomain.err
110510 19:48:18 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data
/usr/local/mysql/libexec/mysqld: Can't find file: './mysql/plugin.frm' (errno: 13)
110510 19:48:18 [ERROR] Can't open the mysql.plugin table. Please run mysql_upgrade to create it.
110510 19:48:18 [ERROR] /usr/local/mysql/libexec/mysqld: Can't create/write to file '/usr/local/mysql/data/localhost.localdomain.pid' (Errcode: 13)
110510 19:48:18 [ERROR] Can't start server: can't create PID file: Permission denied
110510 19:48:18 mysqld_safe mysqld from pid file /usr/local/mysql/data/localhost.localdomain.pid ended
[root@localhost data]#
빨간글씨에 주목...  /usr/local/mysql/data 이곳의 소유권이 root 이기 때문에 일어나는 문제...
앞서 말했듯이 mysql 은 특정 사용자명을 만들어서 (여기에서는 "mysql" 이라고 사용자 생성, 사용자생성과 configure 옵션 참조) 실행시키는데...
root 가 소유자인 data디렉토리에 db data 를 저장 하려고 하니 퍼미션에러가 나는것이다.
권한 변경보다는 소유자를 변경하는편이 보안상 좋다.

[root@localhost data]# chown -R mysql:mysql /usr/local/mysql/data

-R 은 하위 디렉토리 까지 권한을 변경하겠다는 뜻

[root@localhost bin]# ./mysqld_safe &
[1] 11935
[root@localhost bin]# 110510 19:54:18 mysqld_safe Logging to '/usr/local/mysql/data/localhost.localdomain.err'.
110510 19:54:18 mysqld_safe Starting mysqld daemon with databases from /usr/local/mysql/data

[root@localhost bin]#
[root@localhost bin]# ps -ef | grep mysqld
root     11935  2422  0 19:54 pts/0    00:00:00 /bin/sh ./mysqld_safe
mysql    11983 11935  0 19:54 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/localhost.localdomain.err --pid-file=/usr/local/mysql/data/localhost.localdomain.pid
root     11987  2422  0 19:55 pts/0    00:00:00 grep --color=auto mysqld
[root@localhost bin]#


mysql 을 띄우고 프로세스 까지 확인!

7. 관리자 암호 설정
[root@localhost bin]# ./mysqladmin -u root password 12345
[root@localhost bin]#

8. mysql 접속
[root@localhost bin]#
[root@localhost bin]# ./mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.1.57 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| test               |
+--------------------+
3 rows in set (0.00 sec)

mysql>

종료 :
mysqladmin -uroot -p shutdown || kill mysqld

재시작 :
mysqld_safe & safe_mysqld &

동작 여부 :
ps -ef | grep mysql


[출처] http://pippen80.cafe24.com/269

'DEVELOPMENT > Database' 카테고리의 다른 글

Oracle Hint  (0) 2012.05.17
MySQL의 기본 설정 파일(my.cnf)의 위치 확인  (0) 2011.11.29
ORACLE 명령문  (0) 2011.08.02
MERGE INTO 사용법  (0) 2011.07.09
mysql 5.5 db 생성 및 사용자 권한 주기  (0) 2011.03.23