Photo by Caspar Camille Rubin on Unsplash
Install MySQL on Linux
How to Download and Install MySQL on a Linux System
Download the MySQL RPM package
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.
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.
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.
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.
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.
Start and Verify MySQL Service
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.
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.
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.
Exit and Reopen MySQL
Open MySQL Again
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.
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.