While developing your MariaDB system, you might come to a point when you’ll be placing your database files in a non-conventional locations. I’ve been there, and I’m telling you it’s not that easy to do! If you think you’re not up to the challenge, just stick with the default of your OS, but If you’re like me who’ve got special requirements, this article is for you.
First things first
There are a lot of database applications in the wild so I won’t be discussing all of those. Rather, I will be focusing on one database application called MariaDB . Well, ‘don’t ask me why it’s called that way. That’s just what the developers named it. It is an open source database program that allows you to store data in a simple relational way and retrieve those information using structured query language (SQL). It’s ease of use, quality and popularity makes it an ideal database of choice for fast prototyping and deployment, that it’s now being used by various companies such as Google, Wikipedia, Nokia, Samsung among others.
Steps to set up MariaDB with Custom Configuration and Data Directory
So enough of that chit-chat, let’s go to the bread and butter of this article-well, of course, none other than the database application itself. In Linux, there are various ways for you to install MariaDB, However, I won’t be discussing its installation here, because if I do, this article might be too advanced for you, cause some might even end up deleting important files in their operating system, it’s better to know those the basics. The most important thing here is you should have mysqld, mysql_update, and mysql accessible to you.
1. Populate the schema of your data directory:
mysqld –initialize –user=root –datadir=/location/of/my/data
mysql_install_db --user=root --datadir=/location/of/my/data
2. Set up your config file my.cnf ton include your chosen datadir:
[mysqld]
datadir=/location/of/my/data
3. Start the first instance of your database server:
mysqld_safe –defaults-file=/location/of/my.cnf –skip-grant-tables
4. Access mysql instance for the first time:
mysql –defaults-file=/location/of/my.cnf -u root
5. Execute the following in the server prompt:
create database mysql;
use mysql;
select * from user;
truncate table user;
flush privileges;
grant all privileges on *.* to root@localhost identified by ‘YourPassword’ with grant option;
flush privileges;
quit;
6. Terminate the MariaDB server.
7. Restart MariaDB
mysqld_safe –defaults-file=/location/of/my.cnf
So that’s all there is to it! Congratulations on your new configuration and data directory!