Mysql RPM 설치 후 데이터 디렉터리(data_dir) 위치를 변경하려면 어떻게 하나요?
💡 요약 정리
- CentOS 5.x에서 yum으로 설치한 Mysql의 기본 데이터 디렉터리는
/var/lib/mysql입니다. - 데이터 디렉터리를
/home/mysql_DB로 변경하려면 설정 파일을 수정하고 권한을 재설정해야 합니다. - mysql 유저·그룹 권한 설정 및 my.cnf 수정이 관건입니다.
1. 설치 환경
- 운영체제: CentOS 5.x (64bit)
- RPM: mysql-5.0.95-1.el5_7.1
- 새 Mysql 데이터 디렉터리 경로:
/home/mysql_DB
2. 설정 전 기본 정보 확인
- yum(RPM 패키지)로 설치할 경우, 기본 데이터 디렉터리(data_dir)는
/var/lib/mysql입니다. - 아래 절차를 통해 이를
/home/mysql_DB로 변경할 수 있습니다.
3. Mysql 설치
- yum을 사용하여 Mysql을 설치합니다.
[root@cafe24]# yum install mysql-server mysql
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base: ftp.neowiz.com
* extras: ftp.neowiz.com
* updates: ftp.neowiz.com
base | 1.1 kB 00:00
extras | 2.1 kB 00:00
updates | 1.9 kB 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mysql.i386 0:5.0.95-5.el5_9 set to be updated
---> Package mysql.x86_64 0:5.0.95-5.el5_9 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mysql i386 5.0.95-5.el5_9 updates 4.9 M
mysql x86_64 5.0.95-5.el5_9 updates 4.9 M
Transaction Summary
=============================================================================
Install 2 Package(s)
Upgrade 0 Package(s)
Total download size: 9.8 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): mysql-5.0.95-5.el5_9.i386.rpm | 4.9 MB 00:31
(2/2): mysql-5.0.95-5.el5_9.x86_64.rpm | 4.9 MB 00:00
-----------------------------------------------------------------------------------------------------------
Total 294 kB/s | 9.8 MB 00:33
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : mysql 1/2
Installing : mysql 2/2
Installed:
mysql.i386 0:5.0.95-5.el5_9 mysql.x86_64 0:5.0.95-5.el5_9
Complete!
[root@gcafe24 /]#
4. 데이터 디렉터리 생성 및 권한 설정
- yum으로 Mysql을 설치하면
mysql사용자도 자동 생성됩니다. - 변경 경로(
/home/mysql_DB)를 생성하고, 해당 디렉터리에 mysql 사용자 및 그룹 권한을 부여합니다.
[root@cafe24]# mkdir /home/mysql_DB
[root@cafe24]# chown -R mysql /home/mysql_DB
[root@cafe24]# chgrp -R mysql /home/mysql_DB
5. /etc/my.cnf 파일 수정
- 기본 설정 파일 경로:
/etc/my.cnf datadir변경을 반영하려면 아래와 같이 수정합니다.
[root@cafe24]# vi /etc/my.cnf
[mysqld]
datadir=/home/mysql_DB
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
6. Mysql 시작 및 data_dir 확인
- Mysql을 시작하고,
show variables like '%data%';명령어로datadir값이 변경되었는지 확인합니다.
[root@cafe24 mysql_DB]# /etc/rc.d/init.d/mysqld start
Initializing MySQL database: 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/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h gcafe24 password 'new-password'
Alternatively you can run:
/usr/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 ; /usr/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 /usr/bin/mysqlbug script!
The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
Starting mysqld: [ OK ]
[root@cafe24 mysql_DB]#
[root@cafe24 mysql_DB]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.95 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show variables like "%data%";
+----------------------------+------------------------+
| Variable_name | Value |
+----------------------------+------------------------+
| bdb_shared_data | OFF |
| character_set_database | latin1 |
| collation_database | latin1_swedish_ci |
| datadir | /home/mysql_DB/ |
| innodb_data_file_path | ibdata1:10M:autoextend |
| innodb_data_home_dir | |
| max_length_for_sort_data | 1024 |
| myisam_data_pointer_size | 6 |
| skip_show_database | OFF |
| updatable_views_with_limit| YES |
+----------------------------+------------------------+
10 rows in set (0.00 sec)
mysql>