Free, open-source MySQL is one of the most popular database management systems. MySQL is used as a database backend for websites and web-based applications. It is very popular due to its stability, robustness, and ease of use. Also, MySQL is compatible with all major Linux operating systems, including Fedora, Debian, Ubuntu, CentOS, and more. It is primarily used with LAMP and LEMP stack to host web applications.
This post will show you how to install MySQL server on Fedora.
Step 1 – Add MySQL 8 Repository
The MySQL 8 package is not included in the Fedora official repository by default, so you will need to create a MySQL repo in your server. You can create it by running the following command.
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-fc34-2.noarch.rpm rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
Next, verify the added repo using the following command.
dnf repolist all | grep mysql | grep enabled
You should see the MySQL repo in the following output.
mysql-connectors-community MySQL Connectors Community enabled mysql-tools-community MySQL Tools Community enabled mysql80-community MySQL 8.0 Community Server enabled
Step 2 – Install MySQL 8
You can now install the MySQL community server package using the following command.
dnf install mysql-community-server -y
Once MySQL is installed, start and enable the MySQL service using the following command.
systemctl enable mysqld systemctl start mysqld
Next, check the status of the MySQL service with the following command.
systemctl status mysqld
You should see the following output.
● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Sat 2023-04-22 03:19:40 EDT; 7s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 7609 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 7681 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 4666) Memory: 455.2M CPU: 6.985s CGroup: /system.slice/mysqld.service └─7681 /usr/sbin/mysqld Apr 22 03:19:30 fedora systemd[1]: Starting MySQL Server... Apr 22 03:19:40 fedora systemd[1]: Started MySQL Server.
Next, verify the MySQL version with the following command.
mysqld --version
You will get the following output.
/usr/sbin/mysqld Ver 8.0.28 for Linux on x86_64 (MySQL Community Server - GPL)
Step 3 – Secure MySQL Installation
The MySQL root password is set during the MySQL installation, you can retrieve it from its log file.
grep 'A temporary password is generated' /var/log/mysqld.log | tail -1
You should see the MySQL root password in the following output.
2023-04-22T07:19:33.946612Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 3ksZatoy
Next, run the following script to secure the MySQL installation.
mysql_secure_installation
You will be asked to set a new MySQL password as shown below.
Securing the MySQL server deployment. Enter password for user root:
Provide your existing root password and press the Enter key. You will be prompted to set a new password.
The existing password for the user account root has expired. Please set a new password. New password: Re-enter new password:
Set your new password and press the Enter key. You will be asked to remove the anonymous user.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Type Y and press the Enter key. You will be asked to disallow root login.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Type Y and press the Enter key. You will be asked to remove the test database.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
Type Y and press the Enter key. You will be asked to reload the privileges table.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Type Y and press the Enter key to finish securing MySQL.
Step 4 – Create a Database and User in MySQL
First, log in to MySQL shell using the following command.
mysql -u root -p
Provide your root password to log in, then create a database and user using the following command.
CREATE DATABASE testdb; CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'Your1_S@ecu&re*Pa(sswo)r-d';
Next, grant all the privileges to testdb database with the following command.
GRANT ALL PRIVILEGES ON testdb.* TO testuser@localhost;
Next, flush the privileges and exit from MySQL using the following command.
FLUSH PRIVILEGES; EXIT;
Step 5 – Uninstall MySQL Server
To remove the MySQL server from your system, run the following command.
dnf remove mysql-community-server
Next, clear the package cache using the following command.
dnf clean all
Next, remove the MySQL data directory.
rm -rf /var/lib/mysql
Conclusion
This tutorial showed you how to install MySQL 8 on Fedora. We also explained how to secure the MySQL installation, set a root password and create a database and user. You can now easily install and manage MySQL on your server. Try to install MySQL server on dedicated server hosting from Atlantic.Net!