Quick Setup MariaDB
This is a quick guide on how to setup MariaDB. It includes how to secure the installation, create a database and make a user with authentication. This guide uses Debian, package installation instructions may differ from distro to distro.
Installing MariaDB
First update the repos and upgrade any packages before installing MariaDB:
sudo apt update
sudo apt upgrade
Then install the MariaDB package:
sudo apt install mariadb-server
Securing your MariaDB installation
Once installed, we do a quick run through of the security setup for MariaDB:
sudo mysql_secure_installation
It will then take you through a small script to secure your MariaDB server for production. Adjust accordingly if you have different needs.
Enter current password for root (enter for none): [ENTER]
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] n
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y
Creating the database & user
Now we can login to MariaDB as the root user to create our database:
sudo mysql -u root
Then we will proceed to make the database with the name exampledb
and a user called exampleuser
with full grant privileges to the exampledb
database.
Make sure to change the password
value to something more secure in production systems!
CREATE DATABASE exampledb;
CREATE USER 'exampleuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON exampledb.* TO 'exampleuser'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
EXIT;
You have successfully installed MariaDB and created a user with full grant privileges to a database. For most software, this is all you need to setup on the MariaDB side. Always check the documentation to see if any additional options are required!