{"id":8729,"date":"2020-06-29T04:52:15","date_gmt":"2020-06-29T08:52:15","guid":{"rendered":"http:\/\/local.brightwhiz\/?p=8729"},"modified":"2021-12-04T08:31:02","modified_gmt":"2021-12-04T08:31:02","slug":"install-mariadb-on-ubuntu-20-04","status":"publish","type":"post","link":"http:\/\/local.brightwhiz\/install-mariadb-on-ubuntu-20-04\/","title":{"rendered":"How to Install MariaDB on Ubuntu 20.04 LTS [Latest Release]"},"content":{"rendered":"\n
Today we will show you how to install the MariaDB database server on your Ubuntu 20.04 LTS system. Our focus is a variation allowing you to install and maintain the latest version.<\/p>\n\n\n\n
MariaDB<\/a> is an open-source relational database<\/a> management system. Developed by the original MySQL<\/a> developers, it can be used as an alternative to MySQL as it maintains high compatibility with the MySQL server, APIs and commands and is, therefore, a drop-in replacement for MySQL.<\/p>\n\n\n\n Before you get started, you will need a server running Ubuntu<\/a> 20.04 LTS with a non-root administrative user and a firewall configured with UFW.<\/p>\n\n\n\n Like many of the default packages in Ubuntu, the repositories contain old versions of the MariaDB server. Therefore, we will have to import the official MariaDB repository and use it to get the latest version of MariaDB.<\/p>\n\n\n\n Add the package signing key to your system by running the following commands:<\/p>\n\n\n\n Next, create the apt configuration file on your Ubuntu system by running the following command:<\/p>\n\n\n\n Add this content to the configuration file.<\/p>\n\n\n\n Save and exit the file.<\/p>\n\n\n\n Now that we have access to the official MariaDB repository, we are ready to install the latest version of MariaDB.<\/p>\n\n\n\n We can install the MariaDB server, client tools, and other required packages by running the following commands:<\/p>\n\n\n\n We now have to use the command-line utility provided by MariaDB to complete the post-installation steps. This additional setup allows you to configure a secure password for the root user and remove insecure default installation settings.<\/p>\n\n\n\n Run the following command in your terminal.<\/p>\n\n\n\n This will guide you through a series of prompts where you can make your desired changes to your MariaDB installation\u2019s security options.<\/p>\n\n\n\n The script starts off by asking for the current database root password. Since you have not set one up yet, press ENTER<\/strong> to proceed.<\/p>\n\n\n\n Output:<\/p>\n\n\n\n Next, you will be asked whether you would like to set up a database root password. Ideally, you will want to set up a password here. However, with Ubuntu the root account for MariaDB is tied closely to automated system maintenance like log rotation, starting and stopping the server, and more.<\/p>\n\n\n\n This presents a potential problem in the future. This presents the possibility for a package update to break the database system by removing access to the administrative account, so we should not change the configured authentication methods for that account.<\/p>\n\n\n\n For this prompt, just type N<\/strong> and then press ENTER<\/strong>.<\/p>\n\n\n\n Output:<\/p>\n\n\n\n For the next series of prompts, the recommended options are to select yes (‘Y’)<\/strong>.<\/p>\n\n\n\n These will basically remove anonymous users, the test database, disable remote root logins, and load these new rules so that MariaDB immediately implements the changes you have made.<\/p>\n\n\n\n On Ubuntu systems running MariaDB 10.3+, the root MariaDB user is set to authenticate using the unix_socket plugin by default rather than with a password.<\/p>\n\n\n\n This is well and okay from a security and usability standpoint in most cases, but it can also affect the operations of an external program like phpMyAdmin to access administrative rights.<\/p>\n\n\n\n You can create a user that has the same capabilities as the root user but is configured for password authentication. In our example, we will call this user admin.<\/p>\n\n\n\n Go to the terminal and run this command to open up the MariaDB prompt:<\/p>\n\n\n\n create a new user with root privileges and password-based access using your own user and password combination.<\/p>\n\n\n\n Next, Flush the privileges to save and have the changes available in the current session:<\/p>\n\n\n\n You may now exit the MariaDB shell.<\/p>\n\n\n\n You can test that MariaDB is started by running the following command:<\/p>\n\n\n\n You\u2019ll see some output similar to this:<\/p>\n\n\n\n Output:<\/p>\n\n\n\n You can use Ubuntu’s systemd<\/strong> to manage the MariaDB service. These are the four commands you would tend to use at different scenarios:<\/p>\n\n\n\n If you have successfully come this far you now have a working database service that has been secured using the mysql_secure_installation script, and an administrative user to handle the root user tasks.<\/p>\n\n\n\n That is all there is to install MariaDB on Ubuntu 20.04 LTS. From here you will need to start creating your databases, additional users, and start managing your data. <\/p>\n\n\n\n Next, you can install phpMyAdmin to do all the above via a web-based interface. You can also invest in a tool like Webyog’s SQLYog<\/a> which includes a free community edition<\/a> or purchase a license here<\/a>. You can also use it to manage your MariaDB database.<\/p>\n","protected":false},"excerpt":{"rendered":" Today we will show you how to install the MariaDB database server on your Ubuntu 20.04 LTS system. Our focus is a variation allowing you to install and maintain the…<\/p>\n","protected":false},"author":1,"featured_media":8730,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,9,28,16],"tags":[164,177,180,313,354,365,393,424,433,449,526,531,598],"yoast_head":"\nPrerequisites<\/h2>\n\n\n\n
Step 1 \u2013 Setup Repository<\/h2>\n\n\n\n
$ sudo apt install software-properties-common\n$ sudo apt-key adv --fetch-keys 'https:\/\/mariadb.org\/mariadb_release_signing_key.asc'<\/code><\/pre>\n\n\n\n
$ sudo nano \/etc\/apt\/sources.list.d\/mariadb.list<\/code><\/pre>\n\n\n\n
# MariaDB 10.4 Repository\ndeb [arch=amd64] http:\/\/nyc2.mirrors.digitalocean.com\/mariadb\/repo\/10.4\/ubuntu focal main\ndeb-src http:\/\/nyc2.mirrors.digitalocean.com\/mariadb\/repo\/10.4\/ubuntu focal main<\/code><\/pre>\n\n\n\n
Step 2 \u2013 Install MariaDB on Ubuntu 20.04 LTS<\/h2>\n\n\n\n
$ sudo apt update\n$ sudo apt install mariadb-server<\/code><\/pre>\n\n\n\n
Step 3 \u2013 Post Installation Setup<\/h2>\n\n\n\n
$ sudo mysql_secure_installation<\/code><\/pre>\n\n\n\n
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB\n SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!\n\nIn order to log into MariaDB to secure it, we'll need the current\npassword for the root user. If you've just installed MariaDB, and\nyou haven't set the root password yet, the password will be blank,\nso you should just press enter here.\n\nEnter current password for root (enter for none):<\/code><\/pre>\n\n\n\n
. . .\nOK, successfully used password, moving on...\n\nSetting the root password ensures that nobody can log into the MariaDB\nroot user without the proper authorisation.\n\nSet root password? [Y\/n] N<\/code><\/pre>\n\n\n\n
Step 4 \u2014 (Optional) Create an Administrative User that Uses Password Authentication<\/h2>\n\n\n\n
$ sudo mariadb<\/code><\/pre>\n\n\n\n
MariaDB [(none)]> GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;<\/code><\/pre>\n\n\n\n
MariaDB [(none)]> FLUSH PRIVILEGES;<\/code><\/pre>\n\n\n\n
MariaDB [(none)]> exit<\/code><\/pre>\n\n\n\n
Step 4 \u2014 Test the MariaDB Service<\/h2>\n\n\n\n
$ sudo systemctl status mariadb<\/code><\/pre>\n\n\n\n
mariadb.service - MariaDB 10.4.13 database server\n Loaded: loaded (\/lib\/systemd\/system\/mariadb.service; enabled; vendor preset: enabled)\n Active: active (running) since Tue 2020-06-14 11:18:12 UTC; 4min 25s ago\n Docs: man:mysqld(8)\n https:\/\/mariadb.com\/kb\/en\/library\/systemd\/\n Main PID: 25914 (mysqld)\n Status: "Taking your SQL requests now..."\n Tasks: 31 (limit: 2345)\n Memory: 48.6M\n CGroup: \/system.slice\/mariadb.service\n \u2514\u250025914 \/usr\/sbin\/mysqld<\/code><\/pre>\n\n\n\n
Step 5 \u2013 Manage MariaDB Service<\/h2>\n\n\n\n
$ sudo systemctl start mariadb # To start service \n$ sudo systemctl stop mariadb # To stop service \n$ sudo systemctl restart mariadb # To stop and then start service\n$ sudo systemctl status mariadb # To check status of service <\/code><\/pre>\n\n\n\n
Conclusion<\/h2>\n\n\n\n