Dev.deep
Published on

How to install mysql on linux

Authors

Setting Up Your Database: How to Install MySQL on Linux

MySQL, the open-source relational database management system, is a popular choice for running databases on Linux systems. If you're looking to leverage MySQL's power for your next project, you'll need to get it installed first. Thankfully, the installation process is straightforward and can be done using your Linux distribution's built-in package manager.

Before We Begin

There are two main methods for installing MySQL on Linux: using the official MySQL repositories or using generic binaries. This blog will focus on the method using repositories, which is generally easier and recommended for most users.

1. Adding the MySQL Repository (For Debian/Ubuntu)

The first step involves adding the MySQL repository specific to your Linux distribution. This ensures you get the latest packages compatible with your system. Here's how to do it for Debian and Ubuntu:

sudo apt-get update
sudo apt-get install software-properties-common
sudo apt-key add - < https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/

Replace <URL mysql add repository debian ON dev.mysql.com> with the appropriate repository address based on your desired MySQL version (e.g., for MySQL 8.0, use the provided URL on the MySQL website).

2. Update Package Lists and Install MySQL

Once the repository is added, update your package lists to reflect the new source and then proceed with the installation using the following command:

sudo apt-get update
sudo apt-get install mysql-server

3. Securing Your MySQL Installation

After installation, it's crucial to secure your MySQL server. Run the following command to set a strong root password and remove any test users:

sudo mysql_secure_installation

Follow the prompts to set the root password, remove anonymous users, disallow remote root login, and reload the privilege tables.

4. Verifying the Installation (Optional)

You can verify if MySQL is running correctly by trying to connect to the server using the following command:

sudo mysql -u root -p
mysql linux

Enter the root password you set earlier. If the connection is successful, you'll be greeted by the MySQL command prompt. You can exit the prompt using quit;.