Skip to content

Posts from the ‘Mysql’ Category


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.


Install MySQL in FreeBSD

Login to your machine as root user and Proceed with the given steps:-

1. cd /usr/ports/databases/mysql*-server/

Select the latest MySQL version from /usr/ports/databases/

2. make install clean
3. /usr/local/bin/mysql_install_db
4. chown -R mysql /var/db/mysql/
5. chgrp -R mysql /var/db/mysql/
6. /usr/local/bin/mysqld_safe –user=mysql &
7. /usr/local/bin/mysqladmin -u root password newpassword
8. Open the file /etc/rc.conf and add the following line



backup mysql database dump using shell script

backup_date=`date "+%s"`
/usr/bin/mysqldump -u root bugzilla > /mysql_bkp/bugzilla_$backup_date.sql