Skip to content

Posts tagged ‘mysql’

3
Jan
mysql

Changing mysql data path in Linux

MySQL is a widely used and fast growing SQL database server. Mysql is a Client/Server implementation that consists of (Mysqld) server daemon and various client programs and libraries.

Mysql Data Directory

Data directory is the important part of the Mysql server where all the Data files is getting stored inside the Data folder. By default the same is located in /var/lib/mysql.

Need of changing data path

Some times the database size will go beyond our calculation and this cause to /var partition to run out of space. In this case we need to change the Mysql data folder path another location where we have enough free space.

Follow the steps to Change mysql data path.

Before changing the data path folder stop the Mysql server.

/etc/init.d/mysqld stop

Make a new directory for the data path, where you have enough space.

mkdir /opt/mysql_data

Now we need to copy the existing database in to the new location /opt/mysql_data

cp -R /var/lib/mysql /opt/mysql_data

After copying the database we need to update the new data path file in the my.cnf file.

vi /etc/my.cnf

datadir = /var/lib/mysql

Change it to

datadir = /opt/mysql_data

Now we moved the mysql data directory in to the new location and start the Mysql server to write the DB files to the new location.

/etc/init.d/mysqld start

After staring the Mysql server go to the new location and make sure that all the DB files are updating properly with out any errors.