How to Move the MYSQL Data Directory on SLES 12

  • 7022732
  • 14-Mar-2018
  • 14-Mar-2018


Retain Unified Archiving 4.x
SLES 12+
MySQL 5.6


When MySQL is installed, the default location is put in the /var/lib/MySQL  directory on SLES 12. Keeping the data directory on the root partition can be a risk to use up all of the storage and cause issues with performance, or stability issues with Retain. 

How can the MySQL data directory be moved to a new location on a SLES 12 server?


It is highly recommended that the MySQL data directory is moved to a storage location besides the root partition. This is for stability, and for the storage space. Putting the MySQL on its own partition, the Retain indexes on their own partition, and the Retain archives on their own partition is recommended for optimal performance. 


This knowledgebase (KB) article is provided for informational purposes only and as a courtesy service to you, our customer. MicroFocus Customer Care does not have any database administration (DBA) expertise, nor does it provide DBA services or support. MicroFocus is not responsible for the results of implementing any of the concepts contained in this KB article. Implementation of any of the concepts suggested in this KB article shall be done entirely at your own and sole risk, and MicroFocus does not provide any kind of warranties whatsoever resulting from your decision of implementing any of the KB article’s concepts. It is up to you to do any research and to ensure yourself that any implementation and setup of any of the KB article’s concepts in your database system is correctly and properly executed. It is imperative that you have backups of your database system and storage directory before making any implementation. If you don’t have any DBA expertise, you should consult with a DBA expert before any implementation of the KB article’s concepts.  Under no circumstances, shall Microfocus, or any of its employees, be liable, in contract, tort, delict or otherwise, whether negligence is provable or not, for any direct, indirect, incidental, special, punitive, consequential or other damages, loss, cost or liability whatsoever that would result from or are related to the implementation of any of the concepts suggested in the KB article.

To the extent permitted by applicable law, MicroFocus shall not be liable to you for any special, consequential, direct, indirect or similar damages, including any loss of data, arising out from migrating any type of messages, attachments, database, metadata in your Retain system to another server and/or location.

1.       1). After the initial install of MySQL, start MySQL (rcmysql start) . This will help to ensure that the installation was successful, and that the MySQL is running.

2.       2). Stop MySQL – (rcmysql stop)

3.       3). Create the directory structure where the MySQL data is going to be stored. Create a directory in there as well called temp. This is where the temporary file for MySQL will go instead of the default root partition. 

4.       4) .Copy  the mysql directory to the new location. – cp –ar /NEWPATH

5.       5). Change the ownership of the mysql directory: chown –R mysql:mysql /NEWPATH

6.       6). (optional but recommended) Change the permissions of MYSQL: chmod 755 /NEWAPATH

7.       7). Edit the my.cnf file found in /etc/ directory.

a.       Change the datadir= to the new path (i.e. datadir=/mysqldata/mysql)

b.       Change the socket under [mysqld] to the new path (i.e. socket=mysqldata/mysql/mysql.sock)

c.       Add in the line: tmpdir= [pathtotempdirectory/temp]

d.       At the bottom of the file add in the following lines: 



8.       8). Go to the newpath/mysql

a.       Remove the ib_logfile0 and ib_logfile1 files. (rm ib_logfile*)

b.       Start MySQL. (rcmysql start)

Note: If the mysql service doesn’t start, check the log file in /var/log/mysql for details on why it is not starting. Check the ownership and rights and go through all of the above settings again.  

9). Once rcmysql starts check the status by typing rcysql status  and verifying that it is actively running.

      Proceed with creating a password: mysql_secure_installation. 

      If importing a retain database from another server, create the retain database first, and proceed with the important. See the Retain documentation to create a retain database. 


Additional Information

To remove the directory and contents from /var/lib/mysql  unmount the directory from the btrfs in SLES 12 : umount /var/lib/mysql

This will allow the directory to be removed successfully.

If moving from another server and importing a retain database follow the instructions in this kb here