Open In App

How to Install MySQL/MariaDB in Linux?

Last Updated : 16 Apr, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

Installing MySQL or MariaDB in Linux is a straightforward process that provides you with powerful relational database management systems (RDBMS). MySQL and MariaDB are both widely used for web applications, data storage, and other database tasks. They offer similar features, and MariaDB is often seen as a more feature-rich, community-driven alternative to MySQL. Both databases are compatible with popular programming languages and frameworks, making them versatile choices for developers.

In this guide, you’ll learn how to easily install MySQL or MariaDB on Linux, depending on your preferences and needs. Let’s get started!

How to Get Started with MySQL/MariaDB?

Here’s how to install MySQL or MariaDB on your Linux system. Both of these database management systems are widely used and offer powerful and efficient data handling capabilities. The installation process can vary slightly depending on your Linux distribution, but it typically involves updating your package list and using the package manager to install the desired database server.

Follow the steps below to install MySQL or MariaDB and start using these databases for your applications.

Step 1: Update Package Repository

Before we Install the MySQL/MariaDB, we should update the package repository to ensure that we are installing the latest available versions. Open the terminal and run the following command:

sudo apt update

How to Install MySQL/MariaDB in Linux?

Step 2: Install MySQL/MariaDB Server

Now that we have updated the packages we need to install the main file that is MySQL/MariaDB server and client and to that run the command in the terminal as follows:

sudo apt install mariadb-client mariadb-server

How to Install MySQL/MariaDB in Linux?

The above command will prompt you to confirm the installation, type ‘Y’ for yes and hit enter.

Step 3: Secure MySQL/MariaDB Installation

After the installation of the MySQL/MariaDB, it is essential to secure you installation and we can do this by running the security script that is included with MySQL/MariaDB. simply run the command in the terminal as follows:

sudo mysql_secure_installation

How to Install MySQL/MariaDB in Linux?

The script will guide you through several security options, including setting a root password and removing any anonymous users, disallowing remote root login, and removing test databases. follow the prompts and make selections according to your security preferences.

Step 4: Start and Enable MySQL/MariaDB Service

Once MySQL/MariaDB is installed and secured, you need to start and enable the MySQL/MariaDB service to ensure it starts automatically upon system boot. Run the following commands:

sudo systemctl start mysql
sudo systemctl enable mysql

How to Install MySQL/MariaDB in Linux?

This will start the MySQL/MariaDB service and enable it to start at boot time.

Step 5: Verify MySQL/MariaDB Installation

To verify that MySQL/MariaDB is installed and running correctly, you can use the following command to check the service status:

sudo systemctl status mysql

How to Install MySQL/MariaDB in Linux?

If the service is running properly, you should see an output indicating that the service is active and running.

Step 6: Access MySQL/MariaDB Shell

You can access the MySQL/MariaDB shell by typing the following command and entering the root password when prompted:

sudo mysql -u root -p

How to Install MySQL/MariaDB in Linux?

This will allow you to login into the Database shell, that will allow you to run SQL queries and manage database.

Conclusion

In conclusion, installing MySQL or MariaDB on Linux is an easy process that can be accomplished using your distribution’s package manager. Whether you choose MySQL or MariaDB, both provide robust and efficient database management solutions. By following the installation instructions for your specific Linux distribution, you can quickly set up and begin using these powerful databases for your applications. Be sure to stay informed about any version or compatibility issues to maintain a smooth experience.

How to Install MySQL/MariaDB in Linux? – FAQs

Can I install MySQL and MariaDB?

Yes, you can install both MySQL and MariaDB on your system, but it’s important to note that they serve similar purposes as relational database management systems and may conflict with each other if not managed properly.

How to use MySQL in MariaDB?

MariaDB is compatible with MySQL, allowing you to use MySQL databases and commands in MariaDB easily. You can connect to a MariaDB server using the same parameters as MySQL. MariaDB supports MySQL storage engines and works with MySQL replication.

How to start MariaDB in Linux command?

The way to start MariaDB in Linux depends on your system’s init system:

Systemd (Most modern systems):

systemctl start mariadb

System V init (Older systems):

service mysql start

How to change MySQL to MariaDB in Linux?

To change from MySQL to MariaDB in Linux, you need to uninstall MySQL and install MariaDB. Here’s a brief overview of the process:

  1. Back Up Data: Export your MySQL databases.
  2. Stop MySQL: Stop the MySQL server.
  3. Uninstall MySQL: Remove MySQL packages.
  4. Install MariaDB: Install MariaDB server and client.
  5. Import Data: Restore your backup data into MariaDB.

For more detailed instructions on each step, click here to read our full guide on how to change MySQL to MariaDB in Linux.

How to install MariaDB client on Linux?

Installing the MariaDB client on Linux involves using your system’s package manager. The specific commands will differ slightly depending on your distribution:

Debian/Ubuntu:

sudo apt install mariadb-client

CentOS/RHEL/Fedora:

sudo yum install mariadb-client

These commands will install the mariadb-client package, which provides the mysql command-line tool for interacting with MariaDB servers.



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads