MariaDB is a very popular open source database and is widely used in web applications around the world. It was created to provide a free and community-based alternative to MySQL.
MariaDB is compatible with most applications written for MySQL. It is often used as a replacement for MySQL on operating systems such as Ubuntu. Importantly, it offers high availability, performance and scalability, making it an excellent choice for web and server applications.
Ubuntu users, like you, will be able to easily install this database on their web server thanks to this manual. In other words, here you will learn how to install the MariaDB package, configure the database and verify the installation. Read on to find out.
Before starting the installation, it is first important that you update your system. This way, you ensure that you are using the latest versions of the system packages, thus avoiding any possible problems or version conflicts. To do so, open the terminal and run the following command:
sudo apt-get update
This command will update the list of packages available in the Ubuntu repositories. Then, run the following command to update the packages installed on your system:
sudo apt-get upgrade
This command will upgrade all packages installed on your Ubuntu system to the latest version available.
info Note that some packages may require a confirmation before proceeding with the upgrade. Once the upgrade is complete, you are ready to continue with the installation of MariaDB.
The second step is to add the MariaDB repository to the system. This will allow the system to download and install the latest version of MariaDB available in the repository. To do this, follow these steps:
1. Add the MariaDB repository signing key to the system
This command is used to add this key:
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
2. Add the MariaDB repository to the system: **.
Here is the command to add it:
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirror.23media.com/mariadb/repo/10.7/ubuntu jammy main'
info Here we are using MariaDB version 10.7 and the Ubuntu version is Jammy Jellyfish (22.04)**. If you are using a different version of Ubuntu or want to install a different version of MariaDB, be sure to change the corresponding values in the command.
3. Update the system package list again.
When you have added the MariaDB repository to the system, you must update the system package list again so that the system has access to the latest version of MariaDB. Here is the command to do it:
sudo apt-get update
Now it is time to install the MariaDB package. Once you have added the MariaDB repository to the system, you can install the MariaDB package using the following command in the terminal:
sudo apt-get install mariadb-server
This command will download and install the MariaDB package on your Ubuntu system. During the installation process, you will be prompted to enter a password for the MariaDB root
user. Be sure to choose a secure password and remember it, as you will need it later to log into the database.
Once the installation is complete, the MariaDB service will start automatically and run in the background. You can check if the service is running correctly, using this command:
sudo systemctl status mariadb
This command will show you the current status of the MariaDB service and should indicate that it is running correctly. With this, the installation of MariaDB on Ubuntu has been completed successfully.
By default, the MariaDB installation does not have very strict security settings, which can make the database vulnerable to external attacks.
To improve the security of your MariaDB instance, follow these steps:
sudo mysql_secure_installation
Enter the password for root
MariaDB: Enter the password you chose during the MariaDB installation.
Do you want to change the authentication socket to unix_socket:** Unix_socket authentication in MariaDB uses operating system identity instead of passwords to authenticate users.
Do you want to change the** root
password for MariaDB? If you have chosen a strong password during installation, you can choose not to change it. Otherwise, change the password to one that is secure.
Do you want to remove anonymous access:** We strongly recommend checking "yes " for security reasons.
Do you want to disable remote access to the database for the user** root
? Say "yes " to disable remote access, as this limits access to the database via the command line.
Do you want to remove the test database from MariaDB?** Again say "yes" to remove the test database, as this database is not needed and may be a security risk.
Do you want to load these changes now?** Here again answer "yes" to save the changes and apply them to your MariaDB instance.
info Once you have completed the security script, the security configuration of your MariaDB instance should be more secure and better protected against potential threats.
Now it is time to configure the database for use with a web server, for example Apache or Nginx. To do this, you have to follow these steps:
Here's the command to do it:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Make sure that the "bind-address " and "default_authentication_plugin " parameter settings are as follows.
bind-address = 127.0.0.1
default_authentication_plugin = mysql_native_password
The first line specifies the IP address on which the database server is bound. In this case, the web server running on the same server as the database server. The second line sets the default authentication plugin, which is required for authentication to work with some content management systems, such as WordPress.
When you are done with this step, you need to save and close the configuration file.
You have to do it with this command:
sudo systemctl restart mariadb
Run the following command to log in:
sudo mysql -u root -p
Here's the command you can use to create them:
CREATE DATABASE mydatabase;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
FLUSH PRIVILEGES;
In this command, mydatabase
is the name of the database you want to create, myuser
is the username you are going to create and mypassword
is the password you set for that user. Note that it is important to make sure that the user has all the necessary privileges in the database.
success With these steps, your MariaDB database on Ubuntu 22.04 is configured for use with a web server. And it's ready for you to get the most out of it.
Finally, we will show you how you can grant permissions to users so that they can access the database. Follow these steps and you will know how to do it:
1. Log into MariaDB as user root
.
Here is the command to do it:
sudo mysql -u root -p
With the following command you can do this:
GRANT tipo_de_permiso ON nombre_de_base_de_datos.* TO 'nombre_de_usuario'@'localhost';
In this command, permission_type
is the type of permission you want to grant to the user. Such as SELECT
, INSERT
, UPDATE
, DELETE
, etc. Then, database_name
is the name of the database you want the user to have access to. If you want to grant access to all databases, use the asterisk (*) instead of the database name. Finally, username
is the user name you want to grant permissions to.
3. Update privileges
We show you how:
FLUSH PRIVILEGES;
4. Log out of MariaDB session
To finish, just run this command:
exit;
info With these steps, you have granted permissions to a user to access a specific database in your MariaDB installation on Ubuntu 22.04.
By following the steps outlined in this manual, you can have the MariaDB database installed on your Ubuntu server in no time. Setting up security and granting permissions are critical steps that must be carefully followed to ensure secure and correct access to the database. With MariaDB installed and configured correctly, you can take full advantage of this powerful database management system on your web server.