1

I have installed MariaDB and changed datadir to /tank/mysql and that was working.

After that I had to reinstall MariaDB and I was using:

apt -y remove --purge mariadb-server
apt -y install mariadb-server

and that went ok.

Problem is now that datadir is not changed.

File in which I have changed is same as it was before: /etc/mysql/mariadb.conf.d/60-mariadb.cnf

Code:

[mysqld]
datadir=/tank/mysql

MariaDB is pointing to /var/lib/mysql

I know best solution would be to reinstall whole ubuntu server but that it not the option now.

If there is anything else I can wrote to improve my question, please suggest.

No file contains "/var/lib/mysql" in /etc/mysql folder.

I had already this problem after reinstalling on other server and I could not solve it so on the end I have reinstalled whole server.

Information:

OS: Ubuntu server 16.04

MariaDB version: 10.2.15

1
  • Don't change it at all. Mount your new storage at /var/lib/mysql instead. For example zfs set mountpoint=/var/lib/mysql tank/mysql Oct 23, 2020 at 21:35

5 Answers 5

3

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

1

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.

1

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_*
2
  • What directory are you in when you do the 'rm' for ibdata1 and rm ib_* ? Mar 11, 2020 at 16:18
  • 1
    @Edward_178118 updated my answer
    – iWizard
    Mar 11, 2020 at 17:35
1

Change a Default MariaDB 10.x Datadir :

# mkdir /path/new_mysql_dir
# chown -R mysql:mysql /path/new_mysql_dir

# systemctl stop mariadb

# cp -R -p /var/lib/mysql/* /path/new_mysql_dir

# vim /etc/mysql/mariadb.conf.d/50-server.cnf

[mysqld]: datadir=/path/new_mysql_dir

# systemctl start mariadb
0

No file contains "/var/lib/mysql" in /etc/mysql folder.

It's quite possible that /var/lib/mysql is a compiled in default for use in the event that datadir is not otherwise defined.

You should investigate the cascade of .cnf files and ensure that the /etc/mysql/mariadb.conf.d/60-mariadb.cnf file is actually included.

Run the command mysql --help and look for a line like

Default options are read from the following files in the given order: /etc/mysql/my.cnf /etc/my.cnf ~/.my.cnf

The look for each file and check that if they exist, one then includes /etc/mysql/mariadb.conf.d/*.cnf or similar. If that is missing, you should add it.

2
  • I have tried to edit /etc/mysql/my.cnf to break your theory but without success, datadir still points to default.
    – iWizard
    May 28, 2018 at 20:43
  • I have managed to solved and I will write complete instructions.
    – iWizard
    May 28, 2018 at 20:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .