«   2018/08   »
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Archives
Today
326
Total
1,140,506
안정적인 DNS서비스 DNSEver
관리 메뉴

Blue Breeze

Centos7 Mariadb datadir change 본문

DB&NoSQL/MySQL\MariaDB

Centos7 Mariadb datadir change

푸른바람 C/H 2018.03.07 15:30

MariaDB 설치

yum install mariadb-server mariadb -y
systemctl status mariadb
systemctl enable mariadb

PHP db 관련 기능 설치

sudo yum install php-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsql php-pecl-mongodb php-pecl-redis php-pecl-memcache php-pecl-memcached

datadir 위치변경

datadir 위치확인

select @@datadir;
/var/lib/mysql

mysql datadir 변경

sudo vi /etc/my.cnf

[mysqld]
# datadir=/var/lib/mysql
datadir=/home/mysql_data
# socket=/var/lib/mysql/mysql.sock
socket=/home/mysql_data/mysql.sock
    
[client]
socket=/home/mysql_data/mysql.sock

DIR 변경

cp -rfp /var/lib/mysql/* /home/mysql/
mv /var/lib/mysql /var/lib/mysql.back
ln -sf /home/mysql /var/lib/mysql

SELinux 권한설정

semanage fcontext -a -t mysqld_db_t "/home/mysql(/.*)?"
restorecon -R /home/mysql
systemctl start mysql

mysql Protect 변경

sudo vi /usr/lib/systemd/system/mariadb.service

# Prevent accessing /home, /root and /run/user
#ProtectHome=true
ProtectHome=false

php.ini msyql.sock 변경

pdo_mysql.default_socket=/home/mysql_data/mysql.sock
mysql.default_socket =/home/mysql_data/mysql.sock
mysqli.default_socket =/home/mysql_data/mysql.sock

자동시작 등록

mysql_install_db --datadir=/home/mysql

systemctl start mysql|mariadb 에러

이래저래 /ect/init.d/mysql start --datadir=/home/mysql 은 정상적으로 작동하지만 systemctl start mysql|mariadb 가 되지 않는다면 systemctl 서비스를 변경하라.

cd /usr/lib/systemd/system
mv mariadb.service mariadb.service.back

vi mariadb.service
[Unit]
Description = MySQL Server
After = network.target

[Service]
Type = forking
ExecStart = /etc/rc.d/init.d/mysql start
ExecStop = /etc/rc.d/init.d/mysql stop

[Install]
WantedBy = multi-user.target


systemctl daemon-reload
systemctl start mysql|mariadb
systemctl stop


0 Comments
댓글쓰기 폼