Changing MySQL data directory in CentOS is a very 6 simple steps.

You need root access to your CentOS. Login and do followings

  1. stop the mysql
    #
    # /etc/init.d/mysqld stop
    #
    
  2. copy all the current data to your destination directory (you need to decide where you want to move your mysql data)
    #
    # cp /var/lib/mysql/ /mysqldata/mysql/ -R
    #
    
  3. give your new directory proper rights
    #
    # chown mysql.mysql /mysqldata/mysql/ -R
    #
    
  4. Add new directory path to you my.cnf
    # nano /etc/my.cnf
    #
    #
    [mysqld]
    #datadir=/var/lib/mysql
    datadir=/mysqldata/mysql/
    socket=/var/lib/mysql/mysql.sock
    user=mysql
    # Disabling symbolic-links is recommended to prevent assorted security risks
    symbolic-links=0
    
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    

    see the highlighted lines we changed the “datadir” to our new Path.

  5. Optional you should remove or atleast rename the actual MySQL directory. Just to make sure that you are using new data directory
    #
    # mv /var/lib/mysql /var/lib/mysql_ORIGNAL
    #
    
  6. Start Mysql
    #
    # /etc/init.d/mysqld start
    #