{"id":1840,"date":"2025-07-22T08:00:00","date_gmt":"2025-07-22T05:00:00","guid":{"rendered":"https:\/\/upcloud.com\/global\/us\/resources\/tutorials\/deploying-mariadb-upcloud-beginners-guide\/"},"modified":"2025-07-22T08:00:00","modified_gmt":"2025-07-22T05:00:00","slug":"deploying-mariadb-upcloud-beginners-guide","status":"publish","type":"tutorial","link":"https:\/\/upcloud.com\/global\/resources\/tutorials\/deploying-mariadb-upcloud-beginners-guide\/","title":{"rendered":"Deploying MariaDB on UpCloud: A Beginner\u2019s Guide"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB is an open-source relational database that was originally created as a fork from MySQL. Some of the original developers of MySQL created MariaDB with the purpose of keeping it free and open-source under the GNU general public license.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Being created as a fork, MariaDB is highly compatible with MySQL allowing it in some situations to be used as a drop-in replacement for MySQL without requiring much changes. It also maintains compatibility with MySQL APIs, connectors, and commands.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB offers high-performance, security, and availability features that makes it a perfect fit for many use cases from simple transactional processing systems and web applications, to analytics and data warehouses. It also allows for dynamic horizontal and vertical scalability which makes it suitable for both small-scale and enterprise large-scale applications.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this guide, we\u2019ll cover the step-by-step process for installing MariaDB on an Ubuntu server from <a href=\"https:\/\/upcloud.com\/global\/products\/cloud-servers\">UpCloud<\/a>. We\u2019ll use the Ubuntu APT package manager to download and install the MariaDB server. Then we\u2019ll harden and secure our installation. After that we\u2019ll create a privileged user which we\u2019ll use to access our MariaDB server. Finally, we\u2019ll test creating a database in our server and issuing some queries with our created user.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To follow along with this guide, you\u2019ll need to:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Create an <\/strong><a href=\"https:\/\/signup.upcloud.com\/\"><strong>UpCloud account<\/strong><\/a><strong>:<\/strong> This gives you access to different UpCloud services using the GUI control panel, <a href=\"https:\/\/upcloud.com\/global\/resources\/tools\/upcloud-command-line-interface\">command-line interface<\/a>, or the <a href=\"https:\/\/upcloud.com\/global\/resources\/tools\/category\/api-clients\">API<\/a>.<\/li>\n\n\n\n<li><a href=\"https:\/\/upcloud.com\/global\/resources\/tutorials\/deploy-server\"><strong>Deploy a Cloud server on UpCloud<\/strong><\/a><strong>:<\/strong> This is going to be the server where we\u2019ll install MariaDB. For this guide, we\u2019ll be using an Ubuntu OS image.<\/li>\n\n\n\n<li><strong>Familiarity with using the CLI:<\/strong> We\u2019ll be using some basic commands throughout this guide to install our tools, navigate project directories, and work with SSH.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Installing MariaDB<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB is available in the default APT repositories, so we can use the APT package manager to download and install it on Ubuntu with the following steps:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Update the package repository index. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo apt update<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. Install the MariaDB server and client.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo apt install mariadb-server mariadb-client -y<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">3. Verify the installation by checking the MariaDB version.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">mariadb --version<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You should see the installed version in the output.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">mariadb  Ver 15.1 Distrib 10.11.13-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Check that MariaDB service is running.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo systemctl status mariadb<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/1-systemctl-status-mariadb-1024x408.png\" alt=\"-\" class=\"wp-image-65584\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">If the above output shows that the mariadb server is not running, you can start it manually with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo systemctl start mariadb<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Also if you find the mariadb service is not enabled, you can enable it so that it starts automatically when the server is rebooted with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo systemctl enable mariadb<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Securing the MariaDB Installation<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The MariaDB installation has some default configurations that are not considered security best practices and are intended for simple development and testing purposes. However, the installation is shipped with a script utility called <strong><em>mariadb-secure-installation<\/em><\/strong> that can be executed to improve the security of your installation and fix these security weaknesses.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">When executed, the script prompts you for each action to determine whether you want to apply it or not. These actions are as follows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Set a password for root accounts.<\/li>\n\n\n\n<li>Remove root accounts that are accessible from outside the local host.<\/li>\n\n\n\n<li>Remove anonymous-user accounts.<\/li>\n\n\n\n<li>Remove the test database, which by default can be accessed by all users including anonymous users.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s check and apply these recommended security actions:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Run the script with the following command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo mariadb-secure-installation<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The script will prompt you to enter the root password which is not set by default, so you can just type <strong><em>Enter<\/em><\/strong> for an empty password.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/2-mariadb-secure-installation-1024x529.png\" alt=\"-\" class=\"wp-image-65585\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2. Starting from <a href=\"https:\/\/mariadb.com\/docs\/release-notes\/mariadb-community-server-release-notes\/old-releases\/release-notes-mariadb-10-4-series\/what-is-mariadb-104\" target=\"_blank\" rel=\"noopener\">MariaDB version 10.4<\/a>, the <a href=\"https:\/\/mariadb.com\/docs\/server\/reference\/plugins\/authentication-plugins\/authentication-plugin-unix-socket\" target=\"_blank\" rel=\"noopener\"><strong><em>unix socket authentication<\/em><\/strong><\/a> is enabled by default which removes the need to create a root password. So we can safely ignore the first and second prompt from the script:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/3-mariadb-setting-root-password-1024x464.png\" alt=\"-\" class=\"wp-image-65586\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3. The next prompt asks for removing anonymous users, we should apply that to improve the installation security.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/4-mariadb-remove-anonymous-users-1024x281.png\" alt=\"-\" class=\"wp-image-65587\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">4. The next prompt asks to disable root user remote login from outside localhost, we should also apply that to our installation.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/5-mariadb-disallow-remote-root-1024x203.png\" alt=\"-\" class=\"wp-image-65589\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">5. The next prompt asks for removing the test database that comes by default with the installation, we should apply that.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/6-mariadb-dropping-test-database-1024x299.png\" alt=\"-\" class=\"wp-image-65592\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">6. The final prompt will ask to reload the privilege tables, we need to apply this so that the changes we made take effect immediately.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/7-mariadb-reload-privileges-1024x381.png\" alt=\"-\" class=\"wp-image-65594\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">That\u2019s it! You\u2019ve now improved the security of your MariaDB installation and fixed the weaknesses that come with the default installation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Create a Privileged User With Password Authentication<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In almost any type of server or system it\u2019s always not recommended to use the root user for your operations, and MariaDB is no different. A common practice to avoid this problem is to create another user with administrative privileges to be used instead, and keep the root user only for actions that require it.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s apply this to our MariaDB server by creating an administrative user with the following steps:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1 .Connect to the MariaDB server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">mariadb -u root -p<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">There\u2019s no default password set for the root user, so you can leave it as empty when prompted for the password.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/8-mariadb-login-root-1024x413.png\" alt=\"-\" class=\"wp-image-65597\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">2. Run the following query to create a new user.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <strong><em>username<\/em><\/strong> with the name of the user you want to create, and <strong><em>password<\/em><\/strong> with the password you want to set.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">3. Grant all the privileges to the user you created so that it has administrative permissions.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">4. Now that we\u2019ve the admin user ready, exit the current database server connection which we\u2019re using the root user for.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">EXIT;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Test Database Access With the Admin User<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let\u2019s try to connect to MariaDB again with our newly created admin user and test its permissions:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1. Connect to MariaDB server.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">mariadb -u username -p<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">2. List the current databases in the server with the following command.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">SHOW DATABASES;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/9-mariadb-show-databases-1024x497.png\" alt=\"-\" class=\"wp-image-65599\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">3. List the current existing users with the following query.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">SELECT host, user FROM mysql.user;<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/10-mariadb-list-users.png\" alt=\"-\" class=\"wp-image-65600\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">4. Create a new database with the following query<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">CREATE DATABASE db_name;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Replace <strong><em>db_name<\/em><\/strong> with the name of the database you want to create.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/upcloud.com\/media\/11-mariadb-create-database-1024x385.png\" alt=\"-\" class=\"wp-image-65603\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">We can see that our new database is now listed in the server, and we\u2019ve verified that our user permissions are working fine.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB is a popular open-source relational database that offers high-performance, scalability, and security features that match a wide range of use cases including web applications, analytics, and data warehousing. It can satisfy different application needs from small-scale to enterprise large-scale requirements.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">MariaDB was created as a fork from MySQL making it highly compatible with its APIs, commands, and connectors. This also made it possible to use MariaDB as a drop-in replacement for MySQL in many setups.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">In this article, we covered the steps for installing and configuring MariaDB on Ubuntu. We used the APT package manager to install the MariaDB server package from the default APT repositories. Then we improved the security of our installation by executing the <strong><em>mariadb-secure-installation<\/em><\/strong> script. Finally, we created an admin user and tested its permissions by connecting to the MariaDB server and issuing different queries.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Ready to deploy your MariaDB server in the Cloud? <a href=\"https:\/\/signup.upcloud.com\/\">Try UpCloud<\/a> now and get a high-performance and reliable server infrastructure for your deployment.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"author":85,"featured_media":0,"comment_status":"open","ping_status":"closed","template":"","community-category":[226,223],"class_list":["post-1840","tutorial","type-tutorial","status-publish","hentry"],"acf":[],"_links":{"self":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/1840","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial"}],"about":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/types\/tutorial"}],"author":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/users\/85"}],"replies":[{"embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/comments?post=1840"}],"version-history":[{"count":0,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/tutorial\/1840\/revisions"}],"wp:attachment":[{"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/media?parent=1840"}],"wp:term":[{"taxonomy":"community-category","embeddable":true,"href":"https:\/\/upcloud.com\/global\/wp-json\/wp\/v2\/community-category?post=1840"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}