Maria DB is a popular open-source relational database management system that is compatible with MySQL. It offers high performance, scalability, security, and ease of use. In this blog post, I will show you how to install Maria DB on Ubuntu and expose it to the internet using a simple firewall configuration.
Step 1: Update your system and install Maria DB
Before installing Maria DB, you should update your system to the latest version using the following commands:
sudo apt update sudo apt upgrade
Then, you can install Maria DB using the following command:
sudo apt install mariadb-server
This will install the latest version of Maria DB from the official Ubuntu repositories.
Step 2: Secure your Maria DB installation
After installing Maria DB, you should run a security script that will help you set a root password, remove anonymous users, disable remote root login, and remove test databases. You can run the script using the following command:
sudo mysql_secure_installation
Follow the prompts and answer the questions according to your preferences.
Step 3: Create a database and a user for your application
Next, you need to create a database and a user for your application that will access Maria DB. You can use the mysql
command-line client to do this. First, log in to Maria DB as root using the following command:
sudo mysql -u root -p
Enter your root password when prompted. Then, create a database using the following command:
CREATE DATABASE mydb;
Replace mydb
with the name of your database. Next, create a user using the following command:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
Replace myuser
with the name of your user and mypassword
with a strong password. Then, grant all privileges to the user on the database using the following command:
GRANT ALL ON mydb.* TO 'myuser'@'localhost';
Finally, exit the mysql
client using the following command:
EXIT;
Step 4: Configure your firewall to allow external access to Maria DB
By default, Maria DB listens on port 3306 on localhost only. If you want to expose it to the internet, you need to configure your firewall to allow external access to this port. You can use ufw
(Uncomplicated Firewall) to do this. First, enable ufw
using the following command:
sudo ufw enable
Then, allow access to port 3306 from any IP address using the following command:
sudo ufw allow from any to any port 3306 proto tcp
Alternatively, you can specify a specific IP address or a range of IP addresses that you want to allow access to Maria DB. For example, if you want to allow access from 192.168.0.0/24, you can use the following command:
sudo ufw allow from 192.168.0.0/24 to any port 3306 proto tcp
You can check the status of your firewall rules using the following command:
sudo ufw status
You should see something like this:
Status: active To Action From -- ------ ---- 3306/tcp ALLOW Anywhere 3306/tcp (v6) ALLOW Anywhere (v6)
Step 5: Test your connection to Maria DB from another machine
To test your connection to Maria DB from another machine, you need to have a client program that can connect to Maria DB. You can use mysql
or any other program that supports MySQL protocol. For example, if you have another Ubuntu machine with mysql
installed, you can use the following command to connect to Maria DB:
mysql -u myuser -p -h <your_server_ip>
Replace <your_server_ip>
with the IP address of your server that runs Maria DB. Enter your user password when prompted. You should see something like this:
Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 10.5.12-MariaDB-1ubuntu0.20.04.1 Ubuntu 20.04 Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MySQL [(none)]>
This means you have successfully connected to Maria DB from another machine.
Conclusion
In this blog post, I have shown you how to install Maria DB on Ubuntu and expose it to the internet using a simple firewall configuration. I hope you found this blog post useful and informative. Thank you for reading! 😊