This article was first published in: https://www.itcoder.tech/posts/how-to-install-mariadb-on-ubuntu-20-04/
MariaDB is an open source relational database management system, which is backward compatible and can replace MySQL.
MariaDB was jointly developed by some of the original developers of MySQL and many community members.
This guide will explain how to install and secure MariaDB on Ubuntu 20.04.
We assume that you have administrative rights to the Ubuntu server, or log in to the system as root or as a user with sudo rights.
At the time of writing, the latest version of MariaDB in the Ubuntu software source repository is 10.3. To install it, run the following command:
sudo apt update
sudo apt install mariadb-server
Once the installation is complete, the MariaDB service will start automatically. To verify that the database server is running, enter:
sudo systemctl status mariadb
The output will show that the service is enabled and running:
...
MariaDB server has a script called mysql_secure_installation
, which allows you to easily improve database server security.
Run the script without parameters:
sudo mysql_secure_installation
The script will prompt you to enter the root password:
Enter current password forroot(enter for none):
Because you have not set a root password, just type "Enter".
In the next prompt, you will be asked whether to set a password for the MySQL root user:
Set root password?[Y/n] n
Enter n
. On Ubuntu, MariaDB users use auth_socket
for authentication by default. This plugin will check whether the local system user who started the client matches the specified MariaDB username.
In the next step, you will be asked to remove anonymous users, restrict root user access to the local machine, remove the test database, and reload the permissions table. For all questions, you should answer Y
:
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
To interact with MariaDB server on the terminal command line, use the mysql
client tool or mariadb
. This tool is installed as a dependency of the MariaDB server package.
This auth_socket
plugin will authenticate users through Unix socket file to connect to localhost
. This means that you cannot verify root by providing a password.
To log in to the MariaDB server as the root user, enter:
sudo mysql
You will be shown the MariaDB shell, like the following:
Welcome to the MariaDB monitor. Commands end with; or \g.
Your MariaDB connection id is 61
Server version:10.3.22-MariaDB-1ubuntu1 Ubuntu 20.04Copyright(c)2000,2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> Bye
If you want to use a third-party program, such as phpMyAdmin, to log in to your MariaDB server as root, you have two options.
The first is to modify the authentication method from auth_socket
to mysql_native_password
. You can do it by running the following command:
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'very_strong_password';
FLUSH PRIVILEGES;
The second, the recommended way is to create an administrator user who can access all databases:
GRANT ALL PRIVILEGES ON *.* TO 'administrator'@'localhost' IDENTIFIED BY 'very_strong_password';
You can name this admin user any name you want, but make sure you use a strong password.
We have shown you how to install MariaDB on Ubuntu 20.04. Your database server is now online and running. Next, you can go to learn How to manage MariaDB user account and data.
If you have any questions, please contact us in the following ways:
WeChat: sn0wdr1am86
WeChat group: add the above WeChat, remark the WeChat group
QQ: 3217680847
QQ Group: 82695646
Recommended Posts