[OS]/Embedded&Linux

mysql 설치 & 환경설정 & root 패스워드 설정

하늘을닮은호수M 2007. 9. 4. 09:45
반응형
지금부터는 DB 서버를 설치하겠습니다. mysql은 많은 프로그램과 연동이 가능하며, linux에서 유용하게 사용할 수 있는 DBMS입니다. 4.1.X 버전에서 많은 변화가 있었고, 특히 5.0.X 버전에서는 사용자정의 함수, 트리거등 DBMS가 갖추어야 할 거의 대부분의 기능을 갖추고 있습니다. 그럼 현재 가장 최근 버전을 설치해 보도록 하겠습니다.
(mysql은 다른 프로그램에 비해 설치시간이 오래 걸립니다.. 컴파일 하는 시간이 엄청 오래 걸리죠)

(1) 설치
설치는 성능을 약 10% 정도 끌어올려준다는 static 모드로 설치하겠습니다.

wget http://ftp.superuser.co.kr/pub/mysql/mysql-5.0.21.tar.gz
tar xvfz mysql-5.0.21.tar.gz
cd mysql-5.0.21
CFLAGS="-static -O2 -march=i686 -funroll-loops"
CXXFLAGS="-static -O2 -march=i686 -funroll-loops -felide-constructors -fno-exceptions -fno-rtti"

./configure
--prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data
--disable-shared --enable-assembler
--with-thread-safe-client --with-mysqld-user="mysql"
--with-client-ldflags=-all-static
--with-mysqld-ldflags=-all-static

--with-readline --without-debug
--without-docs --without-bench
--with-charset=euckr


위 설정에서 static 모드로 설치하며, 언어는 많이 사용하는 euckr로 설치합니다.
물론 설치 후에도 my.cnf 파일을 수정하여 유니코드(utf-8)로 설정 가능합니다.
데이터 디렉토리는 /usr/local/mysql/data 에 저장하게 설정합니다.

make && make install
cd ..
rm -rf mysql-5.0.21.tar.gz

이렇게 한방에 컴파일 및 설치까지 합니다. mysql의 소스 디렉토리를 남겨 두었습니다.
이유는 .? 혹시 DB에 다른 필요한 옵션을 주어 다시 ㅤㅋㅓㅍ파일 하는 일이 가끔 있기 때문이죠~

(2) 설정 파일 복사
메모리에 따라서 환경 설정 파일들을 복사해 줍니다.
my-huge.cnf 1~2G
my-large.cnf 512M
my-medium.cnf 128M~ 256M
my-small.cnf 64M 이하
위와같이 나와있지만 위 설정은 db 서버 전용으로 사용했을 때 설정입니다. 기본적을 my-medium.cnf를 복사한 다음 시스템에 맞게 설정해서 사용해야 합니다 .(모든게 그렇듯 절대적인 것이 아닙니다.)
cp /usr/local/mysql/share/mysql/my-medium.cnf /etc/my.cnf
/etc/my.cnf 파일을 편집하여
log-bin=mysql-bin
#log-bin=mysql-bin
이렇게 주석처리 하여 DB 업데이트 로그를 남기지 않는 것이 성능향상에 도움이 됩니다.
하지만, 업데이트 로그는 DB장애 및 DB reprecation 에 필요합니다.


(3) 기본 db 생성
/usr/local/mysql/bin/mysql_install_db

(4) mysql 운영 사용자 생성
홈 디렉토리는 필요 없기 때문에 -M 옵션을 주어서 사용자를 생성합니다.
useradd -M mysql

(5) data 디렉토리를 mysql이라는 사용자 권한으로 바꾸어 주어야 합니다.
chown -R mysql:mysql /usr/local/mysql/data

(6) 아무곳에서나 mysql 및 mysqldump 명령어를 실행가능하게 심볼릭 링크를 걸어줍니다.
ln -s /usr/local/mysql/bin/mysql /usr/bin/
ln -s /usr/local/mysql/bin/mysqldump /usr/bin/

(7) mysql 데몬을 실행시킵니다.
/usr/local/mysql/bin/mysqld_safe &

(8) mysql root 비밀번호를 설정합니다.
/usr/local/mysql/bin/mysqladmin -u root password "암호"

(9) 운영중에 조취법&^^
- mysql root 비밀번호 잊어 먹었을 때
killall mysqld
/usr/local/mysql/bin/mysqld_safe --skip-grant-tables &
mysql
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 2 to server version: 4.0.20-log

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.
mysql> use mysql
Database changed
mysql> update user set password=password('비밀번호') where user='root';
Query OK, 2 rows affected (0.02 sec)
Rows matched: 2 Changed: 2 Warnings: 0

mysql> exit
Bye
killall mysqld
/usr/local/mysql/bin/mysqld_safe &

반응형