• If you are still using CentOS 7.9, it's time to convert to Alma 8 with the free centos2alma tool by Plesk or Plesk Migrator. Please let us know your experiences or concerns in this thread:
    CentOS2Alma discussion

Question MariaDB change data directory location

BrianHyper

New Pleskian
Hi,

I'm trying to change the MariaDB data directory from /var/lib/mysql to /my_folder/mysql.
Everything is good I can log into mysql in command line but plesk give me a hard time with Zend Errors.

I've change my /etc/my.cnf and my /etc/psa/psa.conf to match with the new mysql location but still get problems.

Did I have to change something else or reconfigure something?

Here's the error I get when trying to access my server :


ERROR: Zend_Db_Adapter_Exception: SQLSTATE[HY000] [2002] No such file or directory

Additionally, an exception has occurred while trying to report this error: Zend_Exception
No entry is registered for key 'translate' (Abstract.php:144)

Search for related Knowledge Base articles




Thx for the help!
 
I've create a symbolic link to workaround... it's not a good thing I think but for now it work...
It look like something is still configured to the /var/lib/mysql but I can't figure out where :(

If someone have a better answer it would be really appreciated I will need to do the same thing on other servers soon.
 
Yes I already did that... but still got the problem :(

I just hope that when I'll do a plesk update this will not cause trouble...
 
do you can send correct link?
Warning: Changing the location for a MySQL server is an administrative task which is not officially supported by Plesk. The solution should be applied on your risk.
As an alternative to moving the MySQL data directory to another location, consider mounting a partition from a new disk to the default MySQL data directory location /var/lib/mysql/
  1. Create a backup of /etc/my.cnf(CentOS/RHEL) or /etc/mysql/my.cnf(Debian/Ubuntu)
    # cp /etc/my.cnf{,_backup}
  2. Copy or move all files from /var/lib/mysql to the desired directory and set the permissions:
    # cp -pr /var/lib/mysql /data/mysql
    # chown -R mysql:mysql /data/mysql
  3. Update /etc/my.cnf or /etc/mysql/my.cnf(Debian/Ubuntu) using vi text editor and change the location to where you have copied mysql directory:
    # vi /etc/my.cnf
    datadir=/data/mysql
    Note: Be sure that the path to socket mysql.sock is unchanged in my.cnf and it is /var/lib/mysql. Also the directory /var/lib/mysql itself should present on the server as changing the path to the socket can cause the Plesk to crush.
  4. Create a configuration file:
    # touch /etc/systemd/system/mariadb.service.d/mariadb_custom.conf
  5. Add necessary content into the created file:
    # echo "[Service]" >> /etc/systemd/system/mariadb.service.d/mariadb_custom.conf
    # echo "ProtectHome=false" >> /etc/systemd/system/mariadb.service.d/mariadb_custom.conf
  6. Create a backup of /etc/passwd:
    # cp -a /etc/passwd{,.bak}
  7. Modify the string below in /etc/passwd and set up the new MySQL location:
    mysql:x:27:27:MariaDB Server:/data/mysql:/sbin/nologin
  8. Restart mysqld:
    Debian/Ubuntu:
    # service mysqld restart
    CentOS:
    # service mariadb restart
  9. Update /etc/psa/psa.conf with a path to the new mysql directory:
    MYSQL_VAR_D /data/mysql
  10. In case of Ubuntu 16.04, disable mysql in apparmor:
    Modify file /etc/apparmor.d/usr.sbin.mysqld (create it if it doesn't exist using vi editor), add:
    /usr/sbin/mysqld {
    }
    # rm /etc/apparmor.d/disable/usr.sbin.mysqld
    # apparmor_parser -a /etc/apparmor.d/usr.sbin.mysqld
    # aa-disable /etc/apparmor.d/usr.sbin.mysqld
  11. For CentOS/RHEL, SELinux context should be changed or it should be disabled.
 
Back
Top