I am using CentOS with cPanel. On my server, all MySQL databases save at
/var is 100% full and MySQL has stopped working. How can I move the databases to a new directory like
/home/mysql especially considering that this server is managed with cPanel?
I can't confirm this from cpanel, as I don't have access, but this is an example from the console connected by ssh and sudo to root. There are arguments for using a bind entry in /etc/fstab instead of a symlink, but this works for me.
My normal procedure is to stop mysql, move the directory contents, link the original, and restart mysqld.
I just noticed a similar question, of which this is close to a duplicate of, which mentions some issues of doing that above with selinux enabled; http://crashmag.net/change-the-default-mysql-data-directory-with-selinux-enabled
So if you have selinux there are some additional steps.
if you want to change
Your new data directory MUST be owned by
restart mysql server
I found this step by step guide working for me.
You must install:
View the SELinux context of the default database location for mysql:
Stop the mysqld daemon:
Create a new directory for the new location of the database(s). In this example, /mysql/ is used:
Copy the database files from the old location to the new location:
Change the ownership of this location to allow access by the mysql user and group. This sets the traditional Unix permissions which SELinux will still observe:
Run the following command to see the initial context of the new directory:
The context usr_t of this newly created directory is not currently suitable to SELinux as a location for MariaDB database files. Once the context has been changed, MariaDB will be able to function properly in this area.
Open the main MariaDB configuration file
Save this file and exit.
However, if the audit daemon is running and with him the
The reason for this denial is that mysql is not labelled correctly for MariaDB data files. SELinux is stopping MariaDB from having access to the content labelled as
Run the following command to add a context mapping for mysql. Note that the
This mapping is written to the
Now use the
Now that the mysql location has been labelled with the correct context for MariaDB, mysqld starts:
Confirm the context has changed for mysql:
The location has been changed and labelled, and
Stopping the Default Install/Instance
Clear Current Config
Uninstal the Default Install/Instance
Clear Current Datadir
Clear the 'New' Datadir
Install it again
Check the service status
Start it - just to create a first/default structure
Check the service status
Interrupt the current MySQL server installation
Ensure that you don´t have anymore instance/service running
Move the mysql data directory to '/mysql' partition and create the symbolic link
Check symbolic link and the real path
Set permission on new Datadir
Try to connect (keep in mind that the default install of MySQL doesn´t set a 'pwd' for 'root' user and then you should connect with 'blank password'
Once connected to MySQL, create a new db just to test if it´s working and where MySQL will create folder/file structure
Check if the new db is on the 'new datadir'
Make sure the mysqld is set to start on boot time