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

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

| improve this answer | |
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.

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.