Install MariaDB Linux | Detailed Steps for Ubuntu + Centos
Installing MariaDB on Linux can simplify the daily tasks of maintaining high-performance databases at IOFLOOD. MariaDB offers enhanced security and advanced features for data handling once installed and configured properly. This article explains how to install MariaDB on Linux, helping our clients set up and manage a reliable database system for their dedicated hosting needs.
In this guide, we will walk you through the process of installing MariaDB on Linux. We will cover methods for both APT and YUM-based distributions, delve into compiling MariaDB from source, installing a specific version, and finally, how to use MariaDB and ensure it’s installed correctly.
So, let’s get started and begin installing MariaDB on your Linux system!
TL;DR: How To Install MariaDB Linux?
On most Linux distributions, you can install MariaDB by running the command
sudo apt-get install mariadb-server
.
sudo apt-get update
sudo apt-get install mariadb-server
# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# mariadb-server is already the newest version (1:10.3.29-0ubuntu0.20.04.1).
# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
This command will update your package lists and then install MariaDB server on your Linux system. The output shows that the package is already installed and is the newest version. If MariaDB wasn’t already installed, the output would show the installation process.
This is a basic way to install MariaDB on Linux, but there’s much more to learn about installing and using MariaDB. Continue reading for more detailed information and advanced installation options.
Table of Contents
- Beginner’s Guide to a MariaDB Install
- Install MariaDB from Source Code
- Specific Versions: MariaDB Install
- Use and Verify Your MariaDB Install
- Alternative Database Systems
- Solving MariaDB Install Issues
- What is MariaDB in Linux Systems?
- Practical Uses of a MardiaDB Install
- Next Steps After You Install MariaDB
- Recap: How to Install MardiaDB
Beginner’s Guide to a MariaDB Install
MariaDB is an open-source relational database management system (RDBMS) that serves as a drop-in replacement for MySQL. It offers more storage engines, better performance, and additional features compared to MySQL. Whether you’re a web developer, database administrator, or just a tech enthusiast, MariaDB is a valuable tool to have in your Linux arsenal.
Let’s dive into the installation process. We’ll cover how to install MariaDB using two of the most popular package managers: APT (for Debian-based distributions) and YUM (for Red Hat-based distributions).
Install MariaDB Linux with YUM
If you’re using a Red Hat-based distribution like CentOS, you can use the YUM package manager to install MariaDB. Here’s how:
sudo yum update
sudo yum install mariadb-server
# Output:
# Loaded plugins: fastestmirror, langpacks
# Loading mirror speeds from cached hostfile
# Resolving Dependencies
# --> Running transaction check
# ---> Package mariadb-server.x86_64 1:5.5.68-1.el7 will be installed
# --> Processing Dependency: mariadb(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-server-5.5.68-1.el7.x86_64
# --> Finished Dependency Resolution
# Dependencies Resolved
This command updates your package lists and then installs MariaDB server along with its necessary dependencies. The output shows the installation process and the packages that have been installed.
Install MariaDB Ubuntu with APT
If you’re using Ubuntu, or a similar Debian-based distribution, you can use the APT package manager to install MariaDB. Here’s how:
sudo apt-get update
sudo apt-get install mariadb-server
# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed:
# mariadb-client-10.3 mariadb-client-core-10.3 mariadb-server-10.3 mariadb-server-core-10.3
# Suggested packages:
# mailx mariadb-test tinyca
# The following NEW packages will be installed:
# mariadb-client-10.3 mariadb-client-core-10.3 mariadb-server mariadb-server-10.3 mariadb-server-core-10.3
# 0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
This command updates your package lists and then installs MariaDB server along with its necessary dependencies. The output shows the installation process and the packages that have been installed.
Install MariaDB from Source Code
While package managers simplify the installation process, sometimes you need to install MariaDB from the source code. This method provides more flexibility, such as installing a specific version or enabling specific features.
Here’s how you can install MariaDB from the source code:
wget https://downloads.mariadb.org/interstitial/mariadb-10.5.9/source/mariadb-10.5.9.tar.gz
tar -xvzf mariadb-10.5.9.tar.gz
cd mariadb-10.5.9
sudo cmake .
sudo make
sudo make install
# Output:
# -- Installing: /usr/local/mysql/bin/mysqld
# -- Installing: /usr/local/mysql/share/english/errmsg.sys
# -- Installing: /usr/local/mysql/scripts/mysql_install_db
# -- Installing: /usr/local/mysql/bin/my_print_defaults
# -- Installing: /usr/local/mysql/bin/mysql_install_db
This script downloads the MariaDB source code, extracts it, compiles it using cmake and make, and finally installs it on your system. The output shows the installation process and the files that have been installed.
Specific Versions: MariaDB Install
There might be scenarios where you need to install a specific version of MariaDB. This could be due to compatibility issues, specific feature requirements, or stability considerations. Here’s how you can install specific versions of MariaDB from source and using popular package managers.
Install MariaDB Versions from Source
The process is similar to the general source installation method, but you need to specify the version you want to install. Here’s an example of installing MariaDB 10.3.29 from source:
wget https://downloads.mariadb.org/interstitial/mariadb-10.3.29/source/mariadb-10.3.29.tar.gz
tar -xvzf mariadb-10.3.29.tar.gz
cd mariadb-10.3.29
sudo cmake .
sudo make
sudo make install
# Output:
# -- Installing: /usr/local/mysql/bin/mysqld
# -- Installing: /usr/local/mysql/share/english/errmsg.sys
# -- Installing: /usr/local/mysql/scripts/mysql_install_db
# -- Installing: /usr/local/mysql/bin/my_print_defaults
# -- Installing: /usr/local/mysql/bin/mysql_install_db
Install MariaDB Versions with APT and YUM
For APT and YUM, you can specify the version of MariaDB you want to install by appending it to the package name. Here’s an example of installing MariaDB 10.3 using APT:
sudo apt-get install mariadb-server=10.3
# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# mariadb-server is already the newest version (10.3.29-0ubuntu0.20.04.1).
# 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
For YUM, the process is similar, but you need to enable the MariaDB repository first:
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=mariadb-10.3
sudo yum install MariaDB-server
# Output:
# Loaded plugins: fastestmirror, langpacks
# Loading mirror speeds from cached hostfile
# Resolving Dependencies
# --> Running transaction check
# ---> Package MariaDB-server.x86_64 0:10.3.29-1.el7.centos will be installed
# --> Finished Dependency Resolution
# Dependencies Resolved
Why Choose One Version Over Another?
Different versions of MariaDB come with different features, performance improvements, and bug fixes. However, newer versions might also introduce changes that could break compatibility with your existing applications. Therefore, it’s essential to balance the benefits of new features and improvements with the potential risks of breaking changes.
Here’s a comparison of some recent MariaDB versions:
Version | Key Features | Compatibility | Performance |
---|---|---|---|
10.5 | ColumnStore storage engine, S3 storage engine, JSON table function | High | High |
10.4 | Instant ALTER TABLE, Application-time periods | Medium | High |
10.3 | System-versioned tables, Oracle compatibility features | Medium | Medium |
Use and Verify Your MariaDB Install
After installing MariaDB, it’s crucial to know how to use it and verify that it’s installed correctly. Here’s how you can do that.
Basic MariaDB Usage
To start using MariaDB, you can use the mysql
command. This command allows you to interact with MariaDB from the command line. Here’s an example of logging into MariaDB as the root user:
mysql -u root -p
# Output:
# Enter password:
# Welcome to the MariaDB monitor. Commands end with ; or \g.
# Your MariaDB connection id is 7
# Server version: 10.5.9-MariaDB-1:10.5.9+maria~focal mariadb.org binary distribution
This command will prompt you for the root password. After entering it, you’ll be logged into MariaDB and can start executing SQL commands.
Verifying MariaDB Install
To verify that MariaDB is installed correctly, you can use the mysqladmin
command to check the server’s status. Here’s how you can do that:
mysqladmin -u root -p version
# Output:
# Enter password:
# mysqladmin Ver 9.1 Distrib 10.5.9-MariaDB, for debian-linux-gnu on x86_64
# Server version 10.5.9-MariaDB-1:10.5.9+maria~focal
# Protocol version 10
# Connection Localhost via UNIX socket
This command will prompt you for the root password. After entering it, it will display information about the MariaDB server, including the server version, protocol version, and connection method. If MariaDB is installed correctly, you should see this information.
Alternative Database Systems
While MariaDB is a robust and versatile database management system, it’s not the only option available for Linux users. Other popular alternatives include MySQL and PostgreSQL. In this section, we’ll introduce these alternatives, provide installation examples, discuss their advantages and disadvantages, and offer recommendations.
Installing MySQL on Linux
MySQL is a widely-used open-source relational database management system. It’s known for its reliability, scalability, and ease of use. Here’s how you can install MySQL on a Linux system using APT:
sudo apt-get update
sudo apt-get install mysql-server
# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed:
# mysql-client-5.7 mysql-client-core-5.7 mysql-server-5.7 mysql-server-core-5.7
# Suggested packages:
# mailx tinyca
# The following NEW packages will be installed:
# mysql-client-5.7 mysql-client-core-5.7 mysql-server mysql-server-5.7 mysql-server-core-5.7
# 0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
With this command, MySQL server and its necessary dependencies are installed on your system. The output shows the installation process and the packages that have been installed.
Installing PostgreSQL on Linux
PostgreSQL is a powerful, open-source object-relational database system. It is robust, feature-rich, and designed to handle a wide range of workloads, from single machines to data warehouses. Here’s how you can install PostgreSQL on a Linux system using APT:
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed:
# postgresql-12 postgresql-client-12 postgresql-client-common postgresql-common sysstat
# Suggested packages:
# postgresql-doc locales-all postgresql-doc-12 libjson-perl isag
# The following NEW packages will be installed:
# postgresql postgresql-12 postgresql-client-12 postgresql-client-common postgresql-common postgresql-contrib sysstat
# 0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
This command installs PostgreSQL and its necessary dependencies on your system. The output shows the installation process and the packages that have been installed.
Comparing MariaDB, MySQL, and PostgreSQL
While MariaDB, MySQL, and PostgreSQL are all reliable and feature-rich database management systems, they each have their unique strengths and weaknesses. Here’s a comparison of these three systems:
Database System | Pros | Cons |
---|---|---|
MariaDB | High compatibility with MySQL, more storage engines, active development | Less widespread use compared to MySQL |
MySQL | Wide adoption, robust support and resources, ease of use | Owned by Oracle, fewer advanced features compared to MariaDB and PostgreSQL |
PostgreSQL | Extensive feature set, high compliance with SQL standards, powerful and flexible | Steeper learning curve, less efficient replication compared to MariaDB and MySQL |
While MariaDB is an excellent choice for many users, you might find MySQL or PostgreSQL better suited to your specific needs. Therefore, it’s essential to understand the strengths and weaknesses of each system and choose the one that best fits your requirements.
Solving MariaDB Install Issues
As with any software installation, you might encounter issues when installing MariaDB on your Linux system. In this section, we’ll discuss some common problems and their solutions. We’ll also provide code examples and tips to help you troubleshoot effectively.
Error: Failed to Start MariaDB Service
After installing MariaDB, you might encounter an error when trying to start the MariaDB service. This can be due to a variety of reasons, such as incorrect configuration or insufficient permissions. Here’s how you can troubleshoot this issue:
sudo systemctl status mariadb
# Output:
# ● mariadb.service - MariaDB 10.3.29 database server
# Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
# Active: failed (Result: exit-code) since Tue 2021-11-30 11:45:07 PST; 2min 15s ago
This command checks the status of the MariaDB service. The output shows that the service has failed to start.
To solve this issue, you can check the MariaDB error log for more detailed information:
sudo tail /var/log/mysql/error.log
# Output:
# 2021-11-30 11:45:07 0 [ERROR] InnoDB: mmap(137428992 bytes) failed; errno 12
# 2021-11-30 11:45:07 0 [ERROR] InnoDB: Cannot allocate memory for the buffer pool
# 2021-11-30 11:45:07 0 [ERROR] InnoDB: Plugin initialization aborted with error Generic error
# 2021-11-30 11:45:07 0 [ERROR] Plugin 'InnoDB' init function returned error.
# 2021-11-30 11:45:07 0 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
# 2021-11-30 11:45:07 0 [ERROR] Unknown/unsupported storage engine: InnoDB
# 2021-11-30 11:45:07 0 [ERROR] Aborting
The error log provides more detailed error messages. In this case, it shows that MariaDB failed to allocate memory for the InnoDB buffer pool. This issue can be resolved by increasing the system’s available memory or reducing the size of the InnoDB buffer pool in the MariaDB configuration file.
Error: MariaDB Package Not Found
When trying to install MariaDB using a package manager, you might encounter an error stating that the MariaDB package could not be found. This can be due to outdated package lists or missing repository information. Here’s how you can troubleshoot this issue:
sudo apt-get update
sudo apt-get install mariadb-server
# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# E: Unable to locate package mariadb-server
This command attempts to update the package lists and install MariaDB. The output shows that the MariaDB package could not be located.
To solve this issue, you can add the official MariaDB repository to your system and then try installing MariaDB again:
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
sudo apt-get update
sudo apt-get install mariadb-server
# Output:
# Reading package lists... Done
# Building dependency tree
# Reading state information... Done
# The following additional packages will be installed:
# mariadb-client-10.3 mariadb-client-core-10.3 mariadb-server-10.3 mariadb-server-core-10.3
# Suggested packages:
# mailx mariadb-test tinyca
# The following NEW packages will be installed:
# mariadb-client-10.3 mariadb-client-core-10.3 mariadb-server mariadb-server-10.3 mariadb-server-core-10.3
# 0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
This script adds the official MariaDB repository to your system, updates your package lists, and then installs MariaDB. The output shows that the MariaDB package has been successfully located and installed.
Remember, encountering issues during installation is not uncommon, and there’s usually a solution available. Don’t be afraid to consult the official MariaDB documentation or seek help from the community if you’re stuck.
What is MariaDB in Linux Systems?
Before diving deeper into the specifics of MariaDB, it’s crucial to understand the fundamental concepts of database management systems (DBMS). A DBMS is a software system that enables users to define, create, maintain, and control access to the database. It provides an organized way of storing, managing, and retrieving information.
MariaDB, like MySQL and PostgreSQL, is a type of DBMS known as a Relational Database Management System (RDBMS). An RDBMS is a DBMS that’s based on the relational model, which stores data in tables made up of rows and columns. This model is highly flexible and efficient, making RDBMSs the most widely used type of DBMS.
Why is Database Management Important in Linux?
Linux, as an open-source operating system, is a popular choice for servers, especially web servers. These servers often require a database to store, retrieve, and manipulate data. This is where a DBMS like MariaDB comes into play.
MariaDB offers a wide range of features that make it a great choice for database management on Linux. It’s open-source, highly compatible with MySQL, offers a wide range of storage engines, and is under active development. Whether you’re running a small blog or a large e-commerce site, MariaDB can handle your database needs.
Practical Uses of a MardiaDB Install
MariaDB is based on SQL (Structured Query Language), a standard language for managing data held in an RDBMS. SQL allows you to query your data in a variety of ways, using English-like statements.
Here’s an example of a basic SQL query in MariaDB:
USE my_database;
SELECT * FROM my_table;
# Output:
# +----+--------+--------+
# | id | name | age |
# +----+--------+--------+
# | 1 | Alice | 20 |
# | 2 | Bob | 22 |
# | 3 | Charlie| 23 |
# +----+--------+--------+
In this example, the USE
statement switches to the my_database
database, and the SELECT
statement retrieves all records from the my_table
table. The output shows the retrieved records.
MariaDB also provides numerous tools and features to help manage your database. For example, the mysqladmin
command allows you to administer your database from the command line. Here’s an example of checking the server’s status using mysqladmin
:
mysqladmin -u root -p version
# Output:
# Enter password:
# mysqladmin Ver 9.1 Distrib 10.5.9-MariaDB, for debian-linux-gnu on x86_64
# Server version 10.5.9-MariaDB-1:10.5.9+maria~focal
# Protocol version 10
# Connection Localhost via UNIX socket
This command checks the status of the MariaDB server. The output shows information about the server, including the server version, protocol version, and connection method.
Understanding these fundamentals will help you better understand how to install and use MariaDB on Linux. Whether you’re a database administrator, a web developer, or a Linux enthusiast, mastering these concepts will be invaluable in your journey with MariaDB.
Next Steps After You Install MariaDB
Database management plays a crucial role in both system administration and web development. As a system administrator, managing databases efficiently ensures smooth operation of various services and applications running on your servers. For web developers, understanding how to interact with databases is essential for building dynamic websites and applications.
Exploring SQL and Database Optimization
SQL (Structured Query Language) is the standard language for managing and manipulating databases. Mastering SQL can help you interact more efficiently with your database, perform complex queries, and even optimize your database’s performance. Here’s an example of a more complex SQL query that uses the JOIN
statement to combine rows from two or more tables:
USE my_database;
SELECT orders.order_id, customers.customer_name, orders.order_date
FROM orders
INNER JOIN customers ON orders.customer_id = customers.customer_id;
# Output:
# +---------+----------------+------------+
# | order_id| customer_name | order_date |
# +---------+----------------+------------+
# | 1 | Alice | 2021-01-01 |
# | 2 | Bob | 2021-02-01 |
# | 3 | Charlie | 2021-03-01 |
# +---------+----------------+------------+
In this example, the JOIN
statement combines the orders
and customers
tables based on a common column, customer_id
. The output shows the combined records.
Database optimization involves tuning your database to achieve better performance and efficiency. This can include optimizing your SQL queries, indexing your database, or even choosing the right database type for your needs.
Further Resources for Mastering MariaDB
If you’re interested in learning more about MariaDB, SQL, or database management in general, here are some resources that can help you deepen your understanding:
- MariaDB’s Official Documentation: This comprehensive resource covers everything from basic MariaDB usage to advanced features and administration.
W3Schools SQL Tutorial: This tutorial provides a good introduction to SQL, covering everything from basic queries to more advanced topics like SQL joins and unions.
Database Performance Blog: This blog offers a wealth of articles on database performance and optimization, with many posts focusing on MariaDB and other open-source databases.
Remember, mastering database management is a journey. Take your time, practice regularly, and don’t hesitate to seek help if you’re stuck. Happy learning!
Recap: How to Install MardiaDB
In this comprehensive guide, we’ve walked through the process of installing MariaDB, an efficient and versatile database management system, on a Linux environment.
We began with the basics, illustrating how to install MariaDB via the package manager on most Linux distributions. We then delved into more advanced topics, exploring how to install specific versions of MariaDB and even how to compile MariaDB from source code. Along the way, we addressed common issues that you may encounter during the installation process and provided solutions to help you overcome them.
Furthermore, we examined alternative approaches to database management, introducing MySQL and PostgreSQL as viable alternatives to MariaDB. We provided examples of how to install these systems and discussed their advantages and disadvantages.
Here’s a quick comparison of these database management systems:
Database System | Pros | Cons |
---|---|---|
MariaDB | High compatibility with MySQL, more storage engines, active development | Less widespread use compared to MySQL |
MySQL | Wide adoption, robust support and resources, ease of use | Owned by Oracle, fewer advanced features compared to MariaDB and PostgreSQL |
PostgreSQL | Extensive feature set, high compliance with SQL standards, powerful and flexible | Steeper learning curve, less efficient replication compared to MariaDB and MySQL |
Whether you’re a system administrator, a web developer, or simply a Linux enthusiast, we hope this guide has provided you with a clearer understanding of how to install MariaDB on Linux and its alternatives.
Mastering MariaDB installation and understanding its alternatives is a valuable skill, whether you’re maintaining a personal blog or managing a large-scale web application. Now, you’re well equipped to handle database management in Linux. Happy coding!