Skip to main content

Home

Moving MySQL data from the default directory to a different directory/host

By default, MySQL uses /var for its data storage. /var directory should be mounted separately on a larger disk. Following are instructions on how to move the /var directory onto a separate location in case of Unravel bundled MySQL and external MySQL.

Unravel bundled MySQL
  1. Perform a slow shutdown of the MySQL server and ensure that it stops without errors.

    1. Get DB root password from /root/unravel.install.include:

      $ grep 'DB_ROOT_PASSWORD' /root/unravel.install.include
      or 
      $ grep 'DB_ROOT_PASSWORD' /root/unravel.install.include.prev
    2. Run the following commands to set MySQL clean shutdown:

      $ /usr/local/unravel/mysql/bin/mysql -uroot --port=3316 --host=127.0.0.1 -p
      mysql> SET GLOBAL innodb_fast_shutdown=0
    3. Stop unravel_db daemon.

      /etc/init.d/unravel_db stop
  2. Backup MySQL database folder. In the following case, steps are run to backup /srv/unravel/db_data folder.

    $ cd /srv/unravel
    $ tar cvf unravel_db_data.tar db_data/
  3. Restore MySQL data directory to the custom path:

    cp unravel_db_data.tar </PATH/TO/NEW/LOCATION>
    cd <NEW LOCATION>
    tar xvf unravel_db_data.tar
    
  4. In /etc/my.cnf, under the [mysqld] section, update the value of data_dir with the new path; data_dir=<new_path>

  5. If the host has been moved, update the JDBC properties in unravel.properties file.

External MySQL

Note

MySQL user needs to have read/write access to the new path.

  1. Perform a slow shutdown of the MySQL server and ensure that it stops without errors.

    1. Run the following commands to set MySQL clean shutdown:

      $ mysql -uroot -p
      $ mysql&gt; SET GLOBAL innodb_fast_shutdown=0
    2. Stop MySQL daemon.

      $ service mysqld stop
  2. Backup /var/lib/mysql/ folder. If you are not using default data path replace /var/lib/mysql/ with the correct path)

    // Backup /var/lib/mysql/ folder (if not using default data path replace /var/lib/mysql/ with the correct path)
    
    $ cd /var/lib
    $ tar cvf unravel_db_data.tar mysql/
  3. Restore MySQL data directory to the custom path:

    cp unravel_db_data.tar </PATH/TO/NEW/SERVER/LOCATION>
    cd <NEW LOCATION>
    tar xvf unravel_db_data.tar
  4. Update /etc/my.cnf file with the new path of the data directory.

  5. If the host has been moved, update JDBC properties in unravel.properties file.

  6. Install JDBC Driver.

Caution

Enabling a slow shutdown can increase the time to stop MySQL.