How to change datadir for MariaDB?
Solution 1:
On Debian 9 I solved by running:
mysql_install_db --datadir=YOURDATADIR
then changing datadir
option in
/etc/mysql/mariadb.conf.d/50-server.cnf
(or whatever file containing datadir
option) according to YOURDATADIR above
and restarting mariadb.service
Solution 2:
Congratulation @CroisOS !
For those who come across a similar problem, here what i did. It is worth to check as it could be the situation your are in.
First, you should find if no other file contains the datadir
directive ( it is just an example ). Run grep -R datadir /etc/mysql/
.
I've once struggle with a such problem too, because systemctl stop|restart mysqld.service
was not working ( the service was not stopped nor restarted at all ). The solution was mysqladmin shutdown
. Ensure the service is not running anymore ( ps faux | grep mysqld
). Then restart the service again with systemctl
.
Check the global variable corresponding to the directive at the mariadb console to ensure the change takes effect.
Solution 3:
Finally I have managed to solve.
NOTE: this is solution only for changing datadir after reinstalling MariaDB, if MariaDB was initially installed it should work by normal change of datadir in cnf file.
# that failed
apt -y remove --purge mariadb-server
apt -y remove --purge mariadb-server-10.2
apt -y autoremove
rm -fr /etc/mysql/
rm -fr /var/lib/mysql
rm /usr/bin/mysql
reboot
# in this moment datadir is /var/lib/mysql
apt -y install mariadb-server
/etc/init.d/mysql stop
cp -R /var/lib/mysql/ /tank/mysql/
cd /tank/mysql/
rm ibdata1
rm ib_*