# Install MySQL on Linux

### Download the MySQL RPM package

```bash
wget https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm
```

This command downloads the MySQL community release package from the official MySQL website. The package will be saved in your current directory, ready for installation.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726136425590/36746c91-f895-4410-bf43-440d140532f3.png align="center")

---

### Install MySQL Server on Linux

In this step, we will install the MySQL Community Server package on your Linux system. After running the command, you will be prompted to confirm the installation.

```bash
sudo dnf install mysql-community-server
```

This command installs the MySQL Community Server along with any required dependencies. It will show you a list of the packages that will be installed. When asked, press "y" to confirm and continue with the installation.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726136685260/a164a375-0520-4d27-a60d-10c776da9729.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726136699577/a36f24de-7900-4822-b8d6-f81b46434000.png align="center")

When prompted with "Is this ok \[y/N\]?", **press 'y'** to proceed with the installation.

---

### Check MySQL Service Status

After installing MySQL, you need to verify whether the MySQL service (mysqld) is active or inactive. The following command will help you check the current status of the MySQL server.

```bash
sudo systemctl status mysqld
```

This command shows the current status of the MySQL service. If it shows **inactive (dead)**, the service is not running. To start it, you will need to enable and start the service manually.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726136770424/e4fcc079-f252-44f2-a63e-7d54ab54864c.png align="center")

---

### Start and Verify MySQL Service

```bash
sudo systemctl start mysqld

sudo systemctl status mysqld
```

The first command starts the MySQL service. The second command checks if the service is running. If successful, you should see **active (running)** in the output, indicating that the MySQL server is operational.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726136866837/2a0f41cb-35fc-4305-acb1-937701a3fb60.png align="center")

---

### Retrieve Temporary MySQL Root Password

After installing MySQL, a temporary password is automatically generated for the root user. You can find this password in the MySQL log file. Use the following command to locate it.

```bash
sudo cat /var/log/mysqld.log | grep "password"
```

This command searches the MySQL log file for the temporary password assigned to the root user. You will need this password to log into MySQL for the first time and change it to something secure.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726136975306/9f06649f-1d5d-4333-84e8-cb6545a2c8aa.png align="center")

---

### Exit and Reopen MySQL

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726137441292/4eb2b8c4-b30f-4f8b-a9cd-cb44eaf5f4fb.png align="center")

### Open MySQL Again

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726137424399/92c8562d-b84d-43df-9371-e8fe942970b3.png align="center")

It opens the MySQL shell again using the root user. You will be prompted to enter the root password (either the temporary password or the one you set). Once entered correctly, you will be logged back into the MySQL shell.

---

### List Databases in MySQL

Once you have successfully logged into MySQL, you can view the available databases. This is useful for ensuring the system is set up correctly and to start working with MySQL databases.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1726137514304/3dfbd75a-2bcf-491c-862e-f4bf43724dcc.png align="center")

This command lists all the default databases in MySQL, such as `information_schema`, `mysql`, `performance_schema`, and `sys`. You should see these databases after running the command if your installation is correct.

---

Congratulations! You have successfully installed MySQL on your Linux system and can now start managing databases. You can create, modify, and query databases using the commands available in the MySQL shell.
