Solved Change of Mariadb 10.3 database location

marcus123

Member

Reaction score: 3
Messages: 37

Hi,

I have installed the Mariadb 10.3 to FreeBSD 11.3, it works well, I would like to change the database directory from the default location (/var/db/mysql) to other location, but it does not work...

I have done below:

- copy /var/db/mysql to the target directory

- rename the /var/db/mysql to /var/db/mysql.bak

- add below to /etc/rc.conf to ensure the proper my.cnf is used:
Code:
mysql_optfile="/usr/local/etc/my.cnf"

- edit my.cnf to add the datadir = the target directory

However, it does not work, it could not use the database on the target directory. When Mariadb is restarted, it would create the mysql database files in /var/db/mysql

any idea?

Many thanks
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 13,892
Messages: 40,608

Set mysql_dbdir to the correct directory in rc.conf.

Code:
# mysql_(instance_)?dbdir (str):        Default to "/var/db/mysql"
#                       Base database directory.

The rc(8) script launches mysqld with the --datadir command line option, which overrules the setting in my.cnf.
 

Quip

Member

Reaction score: 13
Messages: 26

As SirDice noted, you can use mysql_dbdir in rc.conf. I prefer to add symlink to default location. Both ways work if you already have initialized DB.
 

mark_j

Daemon

Reaction score: 871
Messages: 1,449

The rc(8) script launches mysqld with the --datadir command line option, which overrules the setting in my.cnf.

Wow, that's a bit of a gotcha if you come from other OSs and don't want standard install locations.
 
Top