Home > bash, CentOS, Linux, MySQL, RHEL > Install MySQL at non default data directory on different drive on CentOS6.3/RHEL 6

Install MySQL at non default data directory on different drive on CentOS6.3/RHEL 6

We assume the new disk is /dev/sdb1 formatted as ext3
and it will be mounted as /data

# 0. make sure there is no mysqlm mysql data directory :
yum remove mysql mysql-server -y 
test -d /data/mysql/ && rm -rf /data/mysql/
test -d /var/lib/mysql/ && rm -rf /var/lib/mysql/

# 1. install Mysql
yum install mysql mysql-server -y

# 2. check the mysql  status
service mysqld status

# 3. start the mysqld if not started
service mysqld start

# 4. check the mysql status again
service mysqld status

# 5. stop mysqld in case its started, and check thre is n mysql process:
service mysqld stop
ps axu | grep mysql

# 6. make sure the /data partition is added to the /etc/fstab. If not add it:
test  `cat  /etc/fstab | grep /data | wc -l ` -eq 0  && echo "/dev/sdb1 /data ext3  defaults 1 1" >>  /etc/fstab

# 7. make sure the /data partition is mounted, 
test  `cat /proc/mounts  | grep /data | grep -v grep | wc -l` -eq 0 && mount /data

# 8. disable selinx
sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config

# 9. move the mysql data directory to /data partition and create the symbolic link
test -d /var/lib/mysql/ && mv /var/lib/mysql/ /data/ && ln -s /data/mysql /var/lib/
ls -lrth /var/lib/ | grep mysql 

# 10 .make sure the mysqld is set to start on boot time 
chkconfig mysqld on 

# 11. reboot the server in a view to test everything 

# 12. try to use mysql after the reboot:
mysql -NB -e 'select version()'

# 13. set the MySQL root password.

# 14. check the init script :
service mysqld  restart

Slackware4life :)

About these ads
Categories: bash, CentOS, Linux, MySQL, RHEL Tags: , , ,
  1. Renato Pereira
    September 6, 2013 at 8:02 am

    Hi,

    even following your steps, what can ensure that right now you are using ‘/data’ instead the default path ‘/var/lib/mysql’?

    * I think that you forgot to change ‘/etc/my.cnf’

  2. dragkh
    September 6, 2013 at 8:51 am

    well step 9 should do that

    I do assume there is /var/lib/mysql
    in case there is not, that will fail i believe, this is why I added that ls

  3. Joe A.
    November 11, 2014 at 9:54 pm

    This was great!! Thanks.

  1. January 16, 2013 at 4:46 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: