{"id":4773,"date":"2019-09-13T19:48:19","date_gmt":"2019-09-13T22:48:19","guid":{"rendered":"https:\/\/blog.clusterweb.com.br\/?p=4773"},"modified":"2019-09-13T19:48:19","modified_gmt":"2019-09-13T22:48:19","slug":"how-to-install-mariadb-on-debian-10","status":"publish","type":"post","link":"https:\/\/blog.clusterweb.com.br\/?p=4773","title":{"rendered":"How To Install MariaDB on Debian 10"},"content":{"rendered":"<h3 id=\"introduction\">Introduction<\/h3>\n<p><a href=\"https:\/\/mariadb.org\/\">MariaDB<\/a>\u00a0is an open-source database management system, commonly used as an alternative for the MySQL portion of the popular\u00a0LAMP\u00a0(Linux, Apache, MySQL, PHP\/Python\/Perl) stack. It is intended to be a drop-in replacement for MySQL and Debian now only ships with MariaDB packages. If you attempt to install MySQL server related packages, you\u2019ll receive the compatible MariaDB replacement versions instead.<\/p>\n<p>The short version of this installation guide consists of these three steps:<\/p>\n<ul>\n<li>Update your package index using\u00a0<code>apt<\/code><\/li>\n<li>Install the\u00a0<code>mariadb-server<\/code>\u00a0package using\u00a0<code>apt<\/code>. The package also pulls in related tools to interact with MariaDB<\/li>\n<li>Run the included\u00a0<code>mysql_secure_installation<\/code>\u00a0security script to restrict access to the server<\/li>\n<\/ul>\n<p><!--more--><\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt update<\/li>\n<li class=\"line\">sudo apt install mariadb-server<\/li>\n<li class=\"line\">sudo mysql_secure_installation<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>This tutorial will explain how to install MariaDB version 10.3 on a Debian 10 server, and verify that it is running and has a safe initial configuration.<\/p>\n<div data-unique=\"prerequisites\"><\/div>\n<h2 id=\"prerequisites\">Prerequisites<\/h2>\n<p>To follow this tutorial, you will need:<\/p>\n<ul>\n<li>One Debian 10 server set up by following\u00a0this initial server setup guide, including a non-<strong>root<\/strong>\u00a0user with\u00a0<code>sudo<\/code>\u00a0privileges and a firewall.<\/li>\n<\/ul>\n<div data-unique=\"step-1-\u2014-installing-mariadb\"><\/div>\n<h2 id=\"step-1-\u2014-installing-mariadb\">Step 1 \u2014 Installing MariaDB<\/h2>\n<p>On Debian 10, MariaDB version 10.3 is included in the APT package repositories by default. It is marked as the default MySQL variant by the Debian MySQL\/MariaDB packaging team.<\/p>\n<p>To install it, update the package index on your server with\u00a0<code>apt<\/code>:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt update<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>Then install the package:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo apt install mariadb-server<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>These commands will install MariaDB, but will not prompt you to set a password or make any other configuration changes. Because the default configuration leaves your installation of MariaDB insecure, we will use a script that the\u00a0<code>mariadb-server<\/code>\u00a0package provides to restrict access to the server and remove unused accounts.<\/p>\n<div data-unique=\"step-2-\u2014-configuring-mariadb\"><\/div>\n<h2 id=\"step-2-\u2014-configuring-mariadb\">Step 2 \u2014 Configuring MariaDB<\/h2>\n<p>For new MariaDB installations, the next step is to run the included security script. This script changes some of the less secure default options. We will use it to block remote\u00a0<strong>root<\/strong>\u00a0logins and to remove unused database users.<\/p>\n<p>Run the security script:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo mysql_secure_installation<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>This will take you through a series of prompts where you can make some changes to your MariaDB installation\u2019s security options. The first prompt will ask you to enter the current database\u00a0<strong>root<\/strong>\u00a0password. Since we have not set one up yet, press\u00a0<code>ENTER<\/code>\u00a0to indicate \u201cnone\u201d.<\/p>\n<p>The next prompt asks you whether you\u2019d like to set up a database\u00a0<strong>root<\/strong>\u00a0password. Type\u00a0<code>N<\/code>\u00a0and then press\u00a0<code>ENTER<\/code>. In Debian, the\u00a0<strong>root<\/strong>\u00a0account for MariaDB is tied closely to automated system maintenance, so we should not change the configured authentication methods for that account. Doing so would make it possible for a package update to break the database system by removing access to the administrative account. Later, we will cover how to optionally set up an additional administrative account for password access if socket authentication is not appropriate for your use case.<\/p>\n<p>From there, you can press\u00a0<code>Y<\/code>\u00a0and then\u00a0<code>ENTER<\/code>\u00a0to accept the defaults for all the subsequent questions. This will remove some anonymous users and the test database, disable remote\u00a0<strong>root<\/strong>\u00a0logins, and load these new rules so that MariaDB immediately respects the changes you have made.<\/p>\n<div data-unique=\"step-3-\u2014-(optional)-adjusting-user-authentication-and-privileges\"><\/div>\n<h2 id=\"step-3-\u2014-optional-adjusting-user-authentication-and-privileges\">Step 3 \u2014 (Optional) Adjusting User Authentication and Privileges<\/h2>\n<p>In Debian systems running MariaDB 10.3, the\u00a0<strong>root<\/strong>\u00a0MariaDB user is set to authenticate using the\u00a0<code>unix_socket<\/code>\u00a0plugin by default rather than with a password. This allows for some greater security and usability in many cases, but it can also complicate things when you need to allow an external program (e.g., phpMyAdmin) administrative rights.<\/p>\n<p>Because the server uses the\u00a0<strong>root<\/strong>\u00a0account for tasks like log rotation and starting and stopping the server, it is best not to change the\u00a0<strong>root<\/strong>\u00a0account\u2019s authentication details. Changing credentials in the\u00a0<code>\/etc\/mysql\/debian.cnf<\/code>\u00a0configuration file may work initially, but package updates could potentially overwrite those changes. Instead of modifying the\u00a0<strong>root<\/strong>\u00a0account, the package maintainers recommend creating a separate administrative account for password-based access.<\/p>\n<p>To do so, we will create a new account called\u00a0<code>admin<\/code>\u00a0with the same capabilities as the\u00a0<strong>root<\/strong>\u00a0account, but configured for password authentication. To do this, open up the MariaDB prompt from your terminal:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo mysql<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>Now, we will create a new user with\u00a0<strong>root<\/strong>\u00a0privileges and password-based access. Change the username and password to match your preferences:<\/p>\n<pre class=\"code-pre custom_prefix\"><code>MariaDB [(none)]&gt; GRANT ALL ON *.* TO '<span class=\"highlight\">admin<\/span>'@'localhost' IDENTIFIED BY '<span class=\"highlight\">password<\/span>' WITH GRANT OPTION;\r\n<\/code><\/pre>\n<p>Flush the privileges to ensure that they are saved and available in the current session:<\/p>\n<pre class=\"code-pre custom_prefix\"><code>MariaDB [(none)]&gt; FLUSH PRIVILEGES;\r\n<\/code><\/pre>\n<p>Following this, exit the MariaDB shell:<\/p>\n<pre class=\"code-pre custom_prefix\"><code>MariaDB [(none)]&gt; exit\r\n<\/code><\/pre>\n<p>Finally, let\u2019s test the MariaDB installation.<\/p>\n<div data-unique=\"step-4-\u2014-testing-mariadb\"><\/div>\n<h2 id=\"step-4-\u2014-testing-mariadb\">Step 4 \u2014 Testing MariaDB<\/h2>\n<p>When installed from the default repositories, MariaDB should start running automatically. To test this, check its status.<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo systemctl status mariadb<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>You\u2019ll receive output that is similar to the following:<\/p>\n<div class=\"code-label \" title=\"Output\">Output<\/div>\n<pre class=\"code-pre \"><code>\u25cf mariadb.service - MariaDB 10.3.15 database server\r\n   Loaded: loaded (\/lib\/systemd\/system\/mariadb.service; enabled; vendor preset: enabled)\r\n   Active: <span class=\"highlight\">active (running)<\/span> since Fri 2019-07-12 20:35:29 UTC; 47min ago\r\n     Docs: man:mysqld(8)\r\n           https:\/\/mariadb.com\/kb\/en\/library\/systemd\/\r\n Main PID: 2036 (mysqld)\r\n   Status: \"Taking your SQL requests now\u2026\"\r\n    Tasks: 30 (limit: 2378)\r\n   Memory: 76.1M\r\n   CGroup: \/system.slice\/mariadb.service\r\n           \u2514\u25002036 \/usr\/sbin\/mysqld\r\n\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: Phase 6\/7: Checking and upgrading tables\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: Running 'mysqlcheck' with connection arguments: --socket='\/var\/run\/mysqld\/mysqld.sock' --host='localhost' --socket='\/var\/run\/mysqld\/mysqld.sock' --host='localhost' --socket='\/var\/run\/mysqld\/mysqld.sock'\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: # Connecting to localhost\u2026\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: # Disconnecting from localhost\u2026\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: Processing databases\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: information_schema\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: performance_schema\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: Phase 7\/7: Running 'FLUSH PRIVILEGES'\r\nJul 12 20:35:29 deb-mariadb1 \/etc\/mysql\/debian-start[2074]: <span class=\"highlight\">OK<\/span>\r\nJul 12 20:35:30 deb-mariadb1 \/etc\/mysql\/debian-start[2132]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables\r\n<\/code><\/pre>\n<p>If MariaDB isn\u2019t running, you can start it with the command\u00a0<code>sudo systemctl start mariadb<\/code>.<\/p>\n<p>For an additional check, you can try connecting to the database using the\u00a0<code>mysqladmin<\/code>\u00a0tool, which is a client that lets you run administrative commands. For example, this command says to connect to MariaDB as\u00a0<strong>root<\/strong>\u00a0and return the version using the Unix socket:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">sudo mysqladmin version<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>You should receive output similar to this:<\/p>\n<pre class=\"code-pre \"><code><\/code><\/pre>\n<div class=\"secondary-code-label \" title=\"Output\">Output<\/div>\n<pre class=\"code-pre \"><code>mysqladmin  Ver 9.1 Distrib 10.3.15-MariaDB, for debian-linux-gnu on x86_64\r\nCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.\r\n\r\nServer version      10.3.15-MariaDB-1\r\nProtocol version    10\r\nConnection      Localhost via UNIX socket\r\nUNIX socket     \/var\/run\/mysqld\/mysqld.sock\r\nUptime:         48 min 14 sec\r\n\r\nThreads: 7  Questions: 474  Slow queries: 0  Opens: 177  Flush tables: 1  Open tables: 31  Queries per second avg: 0.163\r\n<\/code><\/pre>\n<p>If you configured a separate administrative user with password authentication, you could perform the same operation by typing:<\/p>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<ul class=\"prefixed\">\n<li class=\"line\">mysqladmin -u <span class=\"highlight\">admin<\/span> -p version<\/li>\n<\/ul>\n<pre class=\"code-pre command\"><code><\/code><\/pre>\n<p>This means that MariaDB is up and running and that your user is able to authenticate successfully.<\/p>\n<div data-unique=\"conclusion\"><\/div>\n<h2 id=\"conclusion\">Conclusion<\/h2>\n<p>In this guide you installed MariaDB to act as an SQL server. During the installation process you also secured the server. Optionally, you also created a separate user to ensure administrative access to MariaDB across package updates.<\/p>\n<p>Now that you have a running and secure MariaDB server, here some examples of next steps that you can take to work with the server:<\/p>\n<ul>\n<li>Import and export databases<\/li>\n<\/ul>\n<p>You can also incorporate MariaDB into a larger application stack:<\/p>\n<ul>\n<li>How To Install Linux, Nginx, MariaDB, PHP (LEMP stack) on Debian 10<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction MariaDB\u00a0is an open-source database management system, commonly used as an alternative for the MySQL portion of the popular\u00a0LAMP\u00a0(Linux, Apache, MySQL, PHP\/Python\/Perl) stack. It is intended to be a drop-in replacement for MySQL and Debian now only ships with MariaDB packages. If you attempt to install MySQL server related packages, you\u2019ll receive the compatible MariaDB [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[91,1082,1,730,830,42,51,495],"tags":[1420,17,920,291,1201,923,921],"class_list":["post-4773","post","type-post","status-publish","format-standard","hentry","category-banco-de-dados","category-centos-7-rhel-7","category-viazap","category-clusterweb","category-debian","category-leitura-recomendada","category-linux-linuxrs","category-profissional-de-ti","tag-1420","tag-debian","tag-how","tag-install","tag-mariadb","tag-on","tag-to"],"_links":{"self":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4773","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4773"}],"version-history":[{"count":1,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4773\/revisions"}],"predecessor-version":[{"id":4774,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=\/wp\/v2\/posts\/4773\/revisions\/4774"}],"wp:attachment":[{"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4773"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4773"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.clusterweb.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4773"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}