Open In App

How to Install MySQL on Linux?

Last Updated : 11 Jun, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report

MySQL is one of the most widely used relational database management systems (RDBMS) Known for its reliability, speed, and scalability. MySQL is used for data operations like querying, filtering, sorting, grouping, modifying, and joining the tables present in the database. It is the backbone of many modern applications, powering everything from small websites to large-scale enterprise systems. In this article, we’ll walk explain the process of installing MySQL on Linux, starting from the prerequisites to verifying the installation.

Why Install MySQL on Linux?

Before diving into the installation process, it’s important to understand the features that make MySQL a popular choice for database management:

  • Free & Open Source: MySQL is completely free to use and distribute, which makes it highly accessible to developers and businesses.
  • High Performance & Scalability: With support for indexing, multithreading, and optimization features, MySQL can handle large databases and high-traffic applications with ease.
  • Strong Data Security: MySQL offers robust security features to ensure that your data is protected from unauthorized access.
  • Cross-Platform: MySQL is compatible with various operating systems, including Windows, macOS, and Linux, which makes it highly versatile.
  • Wide Adoption: It is supported by most web hosting providers and integrates easily with popular programming languages and frameworks.

Steps to Install MySQL on Linux

The installation process of MySQL on Linux involves using the terminal and running a series of commands. This articles covers the installation on Ubuntu and other Debian-based distributions, but the steps are similar for other Linux distributions as well.

Step 1: Update Your Package List

Before installing any software, it’s always a good idea to update your package list to ensure you’re getting the latest version available from the repository.

sudo apt update

Step 2: Install MySQL Server

Now, let’s install the MySQL server using the following command. Open terminal using Ctrl+Alt+T then copy and paste the following command in the terminal to install MySQL in Linux.

sudo apt install mysql-server

Install-MySQL-on-Linux_1

Once you run the command, it will prompt you for your password. Enter it and press Enter then Press "y" to continue.

Install-MySQL-on-Linux_2

It will take some time to download and install MySQL in Linux.

Install-MySQL-on-Linux_3

Step 3: Verify MySQL Installation

To verify that MySQL is installed correctly or to know the version enter the following commands in your Terminal.

mysql --version

Verify-MySQL-Installation_1

This confirms that MySQL is installed and ready to use.

Securing Your MySQL Installation

By default, MySQL is installed with some security vulnerabilities, so it's important to secure your installation. MySQL provides a command to set up basic security settings, such as configuring a password for the root user and removing insecure default settings.

Step 4: Run the MySQL Secure Installation Script

Now we will set the VALIDATE PASSWORD component to improve Security

sudo mysql_secure_installation

Protecting-and-Securing-MySQL_1

Then press "y" to set the password. Next press "0" for the low-level password or choose as you want to set the password.

Protecting-and-Securing-MySQL_2

Create a password. Then Re-enter the password, then to continue press "y".

Protecting-and-Securing-MySQL_3-(1)

Now the whole setup is done. Hence, MySQL installaion is successfully done!

MySQL-Successful-Installed-(1)

This script will guide you through several security settings:

  • Set a root password: Choose a strong password for your MySQL root user.
  • Remove insecure default settings: It will prompt you to remove test databases and disable remote root login.
  • Improve password validation: It asks if you want to enable password validation to ensure strong passwords.

Step 5: Test the MySQL Server

Once the security configuration is complete, test whether MySQL is running properly:

sudo systemctl status mysql

If MySQL is running correctly, you should see output indicating that the service is active and running. If not, you can start the MySQL service using:

sudo systemctl start mysql

Getting Started with MySQL

Once MySQL is installed and secured, let’s log into the MySQL shell to start using it.

Step 6: Log into MySQL

To get started with MySQL, type the following command to go to the root directory.  

sudo mysql -u root

You’ll be prompted to enter the root password you set earlier. Once entered correctly, you’ll be logged into the MySQL shell.

Verify MySQL Installation by Creating a Database

To ensure everything is set up properly, let’s create a database and verify that MySQL is working as expected.

Step 7: Create a Database

To create a new database, run the following command within the MySQL shell:

CREATE DATABASE database_name;

Start-Using-MySQL_1-(1)

Step 8: Show Databases

To view the databases on your system, you can use the following command:

SHOW DATABASES;

Start-Using-MySQL_2-(1)

Step 9: Exit MySQL

To exit the MySQL shell, simply type:

EXIT;

Hence, we have successfully created a database using create database command. You are now ready to start using MySQL. MySQL is the best relational database that will keep all your data secure. Many Companies use MySQL because of its solid data security and is supported by multiple applications. So Install MySQL in Linux now and learn SQL in 30 Days - From Basic to Advanced Level!

Conclusion

Congratulations! You’ve successfully installed MySQL on your Linux system and verified its functionality by creating a database. MySQL is now ready for you to start managing your data, running SQL queries, and building robust applications. By following this guide, you’ve also learned how to secure your MySQL installation, which is a crucial step for keeping your data safe. With MySQL installed, you’re now ready to dive deeper into SQL, optimize your databases, and build more sophisticated applications.


Next Article

Similar Reads