Solved Change of Mariadb 10.3 database location

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
 
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.
 
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.
 
Back
Top