MariaDB Installation
Step 1: Update the system
Before installing new software, update your system:
sudo apt update
sudo apt upgrade -yStep 2: Install MariaDB
Install the MariaDB package with the following command:
sudo apt install mariadb-server -yStep 3: Manage the MariaDB service
Start the MariaDB service and make sure it starts automatically on boot:
sudo systemctl start mariadb
sudo systemctl enable mariadbTo check the status of the MariaDB service, use:
sudo systemctl status mariadbStep 4: Secure the MariaDB installation
MariaDB comes with a security script that hardens the installation. Run it to configure basic security options:
sudo mysql_secure_installationFollow the instructions. You will be prompted to do the following:
- Set a root password.
- Remove anonymous users.
- Disallow root login from remote machines.
- Remove the test database.
- Reload the privilege tables.
Step 5: Verify the MariaDB configuration
You can now log in to the MariaDB database to make sure everything works:
sudo mysql -u root -pEnter the root password you set in the previous step. You should land in the MariaDB console:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Server version: 10.3.31-MariaDB-0ubuntu0.20.04.1 Ubuntu 20.04
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>Step 6: Create MariaDB users and databases
Create a new database:
CREATE DATABASE mydatabase;Create a new user and grant them all privileges on the database:
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;Leave the MariaDB console:
EXIT;Step 7: Configure the firewall (optional)
If a firewall is enabled, you have to allow the MariaDB service if you want to access the database remotely:
sudo ufw allow 3306/tcpCheck the firewall status:
sudo ufw statusStep 8: Remote access to MariaDB (optional)
By default, MariaDB is configured to accept only local connections. To change this, edit the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnfFind the line with bind-address and change it from 127.0.0.1 to 0.0.0.0:
bind-address = 0.0.0.0Restart the MariaDB service to apply the changes:
sudo systemctl restart mariadbThis is a basic tutorial for installing and configuring MariaDB. There are many more options and settings you can explore to tailor MariaDB to your specific needs.