How to setup MySQL Database server on Fedora 41 server
Here in this article we will try to setup a basic MySQL server and secure it by updating the root password and removing the defaults.
What is MySQL
MySQL is a popular, open-source Relational Database Management System (RDBMS) that uses Structured Query Language (SQL) to store, manage, and retrieve data in tables. Developed and supported by Oracle Corporation, it is widely used for web applications, offering high speed, reliability, and security.
Test Environment
- Fedora 41 server
Procedure
Step1: Install MySQL server
As a first step we need to install the mysql server package. Here we are specifically installing the mysql8.4-server package available on Fedora 41 server.
admin@linuxser:~$ sudo dnf install mysql8.4-server.x86_64
Step2: Update Firewall for remote access
We need to update firewall settings to open the mysql service port (ie. 3306) so that remote connections to this server can be established.
admin@linuxser:~$ sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
success
admin@linuxser:~$ sudo firewall-cmd --reload
success
Step3: Configure Bind address
Here let’s update the mysql server configuration file to allow mysql server to accept connection from all interfaces.
admin@linuxser:/etc/my.cnf.d$ cat /etc/my.cnf.d/mysql-server.cnf
#
# This group are read by MySQL server.
# Use it for options that only the server (but not clients) should see
#
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/en/server-configuration-defaults.html
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mysqld according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
log-error=/var/log/mysql/mysqld.log
pid-file=/run/mysqld/mysqld.pid
bind-address=0.0.0.0
Step4: Start MySQL server
Let’s now start up the mysql service as shown below.
admin@linuxser:~$ sudo systemctl start mysqld.service
admin@linuxser:~$ sudo systemctl enable mysqld.service
Step5: Secure MySQL server
We are going to run the “mysql_secure_installation” script to update the defaults and secure the service as shown below.
admin@linuxser:~$ sudo mysql_secure_installation
Securing the MySQL server deployment.
Connecting to MySQL using a blank password.
VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?
Press y|Y for Yes, any other key for No: n
Please set the password for root here.
New password:
Re-enter new password:
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y
Success.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y
- Dropping test database...
Success.
- Removing privileges on test database...
Success.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y
Success.
All done!
Step6: Connect to MySQL server
It’s now time to connect to the mysql service using the updated password for root user.
admin@linuxser:~$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.4.5 Source distribution
Copyright (c) 2000, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Step7: Verify Databases and Schemas
Here you can verify the list of schemas and databases that are available as a part of default setup.
mysql> SHOW SCHEMAS;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
Step8: Create Database
Here let’s create a sample database. The utf8_bin collation ensures that string comparisons are case-sensitive and based on the binary value of characters.
mysql> CREATE DATABASE stackdb CHARACTER SET utf8 COLLATE utf8_bin;
Step9: Create user and grant privileges
Let’s now create a user named “stack” and grant all privileges onto the database stackdb. The “%” basically means that the user “stack” can connect to database from any remote host.
If you want the user to connect to database from the server itself you can change “%” with “localhost”.
mysql> CREATE USER 'stack'@'%' IDENTIFIED BY 'stack@1234';
mysql> GRANT ALL on stackdb.* TO 'stack'@'%';
mysql> FLUSH PRIVILEGES;
Now you can connect to the MySQL server remotely using the user “stack” and manage your database.
admin@fedser:~$ mysql -u stack -p
Hope you enjoyed reading this article. Thank you..
Leave a Reply
You must be logged in to post a comment.