How to Setup MySQL on Fedora system
Step 1: Install MySQL Server
Open a terminal and run the following command to install MySQL:
sudo dnf install mysql-server
This will install the MySQL server and client packages.
Step 2: Start and Enable MySQL Service
Once MySQL is installed, you need to start the MySQL service and enable it to start on boot. Start the service:
sudo systemctl start mysqld
Enable it to start on boot:
sudo systemctl enable mysqld
Step 3: Secure MySQL Installation
After starting MySQL, run the security script to secure the installation:
sudo mysql_secure_installation
You will be prompted to:
Set the root password.
Remove anonymous users.
Disallow root login remotely.
Remove the test database.
Reload privilege tables.
Answer 'Y' to all security prompts.
Step 4: Verify MySQL Service Status
To ensure MySQL is running, use the following command:
sudo systemctl status mysqld
It should show that the MySQL service is active and running.
Step 5: Log into MySQL
To log into MySQL as the root user, run:
mysql -u root -p
Enter the root password you set during the security installation.
Step 6: (Optional) Configure MySQL
You can modify MySQL settings by editing the configuration file at /etc/my.cnf
. After any changes, restart the MySQL service:
sudo systemctl restart mysqld
Step 7: Enable Remote Access (Optional)
If you need to access MySQL from a remote server, you will need to update the MySQL configuration.
- Open the MySQL config file:
sudo nano /etc/my.cnf
- Look for the line that says:
bind-address = 127.0.0.1
Change it to:
bind-address = 0.0.0.0
- Save and exit the file. Then restart MySQL:
sudo systemctl restart mysqld
Step 8: Create a Database and User
To create a database and a new user, log into MySQL as root:
mysql -u root -p
Then create a database and user:
CREATE DATABASE my_database;
CREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';
GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';
FLUSH PRIVILEGES;
You now have MySQL fully set up on Fedora 40!
Subscribe to my newsletter
Read articles from Abhay Pratap Maurya directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by