This problem occur when we try to change datadir from default setting to other directory in my.cnf file. This is because SELINUX prevent root user to change even we (root user) can change iy in my.cnf file.
Step 1 – Configure your mysql server
Step 1 – Configure your mysql server
bash#>service mysqld
stop
bash#>mkdir
/DATA/mysql/
bash#>chown
mysql:mysql /DATA/mysql
bash#>mv /var/lib/mysql/*
/DATA/mysql/
bash#>vi /etc/my.cnf
Change
datadir=/var/lib/mysql à
datadir=/DATA/mysql
socket=/var/lib/mysql/mysql.sock à socket=/DATA/mysql/mysql.sock
Step 2 – Configure your SELINUX
to accept your configuration. Usually SELINUX is active by default
installation.
Step2a-Test [semanage] program
available.
bash#>semanage
If the command return “Command not found”. You have to
install “semanage” first. Please go to Step2b.
If not,please proceed with Step 2c
Step2b – Install “semanage”
bash#>yum whatprovides /usr/sbin/semanage
Loaded plugins: fastestmirror,
refresh-packagekit, security
Loading mirror speeds from
cached hostfile
* base: centos.maulvi.net
* extras: centos.maulvi.net
* updates: centos.maulvi.net
policycoreutils-python-2.0.83-19.18.el6.x86_64 : SELinux policy core python utilities
Repo :
base
Matched from:
Filename : /usr/sbin/semanage
bash#>yum -y install policycoreutils-python
Repeat Step2a
Step2c – Configure SELINUX to
accept your settings
bash#>getenforce
bash#>semanage
fcontext -a -t mysqld_db_t "/DATA/mysql(/.*)?"
bash#>restorecon
-Rv /srv/mysql
Step3 – configure your client to
refer to different mysql socket
As default, Mysql Client point to /var/lib/mysql/mysql.sock.
Change or Add this by editing /etc/my.cnf (using your vi editor)
bash#>vi /etc/my.cnf
[client]
socket = /DATA/mysql/mysql.sock
Step4 – Start your server
bash#>service mysqld start
Step5 – Configure your php
webserver (if your webserver same machine and same OS with database server
only)
Edit /etc/php.ini
bash#>vi /etc/php.ini
Change mysql.default_socket = /var/lib/mysql/mysql.sock à mysql.default_socket =
/DATA/mysql/mysql.sock.
Don’t forget to restart your web server
Tiada ulasan:
Catat Ulasan
Please comment, if you think it will help us all.