By default, MySQL location is /var/lib/mysql folder. But, what if your /var directory has less space to store databases?. In such case, you can change the default MySQL location to a new desired path. Below are the exact steps:

Step 1:

Stop MySQL service using below command:

service mysqld stop

Step 2:

Create a new desired directory at where you wish to start storing mysql databases. For example, you create /usr/database directory using below command.

mkdir /user/database

Step 3:
Copy existing databases (/var/lib/mysql) to new location (/usr/database):

cp -€“R /var/lib/mysql /usr/database

Step 4:

Locate MySQL configuration file (usually located at /etc/my.cnf) and change default path of mysql databases:

datadir = /var/lib/mysql
Change it to
datadir = /usr/database

Step 5:

Start mysql service using below command:

Service mysqld start

Accuwebhosting.com