Monday 8 August 2016

Changing Mysql default database directory location

1 Step

Need to stop the mysqld service 

service mysqld stop

2 step

Create a new data diretory and move the content from the old one
Creating a new data directory


mkdir /DB/mysql/

3 step

Change the owner of the directories

chown mysql:mysql /DB/mysql


4 Step

Moving the original data files

mv /var/lib/mysql/* /BD/mysql/

5 step

Correct the MySQL configuration file, Edit the /etc/my.cnf file iwth your favorite editor

vi /etc/my.cnf

Change

datadir=/var/lib/mysql

to

datadir=/DB/mysql

and

socket=/var/lib/mysql/mysql.sock

to

socket=/BD/mysql/mysql.sock

and save the file.

5 step

Disable the selinux

setenforce 0

and vi /etc/selinux/config

change the enforcing to disabled and save and exit.

6 step

start the mysql service

service mysqld start

if it shows mysql Deamon not starting then add the following lines to my.cnf file befor mysqld

[client]

 socket=/DB/mysql/mysql.sock

7 step 

restart the mysqld and try with login

service mysqld restart

mysql  -u root -p

All the best......

No comments:

Post a Comment

Permanent hostname setup for RHEL7

Step 1 Set the host name on NMTUI tool like following nmtui set host name   then save and exit Step 2 add the following l...