There's many reasons that you might want to change the directory that your MySQL data is stored in, such as your partition running out of space or you need to move to a secondary drive. This is an easy task to do, check below. This should work on most Linux distributions and has been tested on CentOS 6.6 and Ubuntu 14.04.
First stop your MySQL server:
service mysqld stop
Now copy your current MySQL data directory to the new directory that you want to use. For this guide we will use "/ssd/mysql" as our new location:
cp -rap /var/lib/mysql /ssd/mysql
Next set proper ownership of the files:
chown mysql.mysql /ssd/mysql
Now we need to edit our MySQL server configuration to reflect the changes, use your favorite text editor to make the changes. We will use nano:
nano /etc/my.cnf
Look for the two following lines:
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
We need to change these to our new location:
datadir=/ssd/mysql
socket=/ssd/mysql/mysql.sock
Save the file and start your MySQL server:
service mysqld start
Your MySQL server will now be using your new data directory.
Update: With certain OS and MySQL versions the above changes may not work, and a symlink will work fine. Use the following steps after you've installed your SQL server.
service mysqld stop / service mariadb stop
mv /var/lib/mysql /home/mysql
ln -s /home/mysql /var/lib/mysql
service mysqld start / service mariadb start
Nejpopulárnější
Install ownCloud on CentOS 6
We will be setting up ownCloud on a fresh CentOS 6.6 64-bit installation. ownCloud is an open...
Install PPTP / PPP Proxy Server on CentOS 6
PPTP Proxy is an easy to setup proxy server that can be used as an OpenVPN alternative, and many...
Install VNC Server and Desktop on CentOS 6
Install the desktop environment that we will use:yum groupinstall Desktop -yInstall the TigerVNC...
Setup Teamspeak 3 Server on Linux (CentOS)
If you run a gaming community, a Teamspeak 3 server is probably a popular choice for you to have...
Setup Plex Media Server on Linux CentOS 7
Looking for a home media server to stream movies, tv shows or music? Plex is a great solution....