Friday, 31 July 2026

Install and Configure MySQL on an Oracle Linux Server

 

Recently, I had the opportunity to work with MySQL and successfully implement it in a project. As part of sharing my experience, I decided to write a blog series on MySQL. In this article, I will explain how to install and configure MySQL on an Oracle Linux server in a simple and easy-to-follow manner.

MySQL is one of the most widely used open-source relational database management systems (RDBMS). It is commonly used for websites, business applications, and other data-driven solutions because it is reliable, scalable, and easy to manage.

Oracle Linux is a secure and stable operating system that provides an excellent platform for running MySQL databases. Due to its performance and enterprise-level features, many organizations choose Oracle Linux for their database environments.

In this blog, we will go through the step-by-step process of installing and configuring MySQL Server on an Oracle Linux server, helping you get your database environment up and running quickly.

MySQL Client-Server Architecture

MySQL uses a client-server architecture. The MySQL Client connects to the MySQL Server using the default port 3306. The server receives and processes SQL queries, then sends the results back to the client. All databases, tables, and log files are stored in the /var/lib/mysql data directory.

Prerequisites

Before you begin, ensure you have:

- An Oracle Linux 8 or Oracle Linux 9 server

- Root or sudo privileges

- Internet connectivity to download packages

- At least 8 GB RAM (recommended)

- Open port 3306 (if remote access is needed)

Step 1: Update the System

It is always a good practice to update the system packages before installing any new software. For this use below command,

sudo dnf update -y

Verify the Oracle Linux version:

cat /etc/os-release

Sample output:

NAME="Oracle Linux Server"

VERSION="9.3"

 Step 2: Check Existing MySQL Packages

Verify whether MySQL is already installed.

rpm -qa | grep mysql

If old MySQL packages exist, remove them if necessary.

sudo dnf remove mysql*

Step 3: Install MySQL Repository

Download and install the MySQL Community Repository package.

For Oracle Linux 8/9:

sudo dnf install https://dev.mysql.com/get/mysql84-community-release-el9-1.noarch.rpm -y

For Oracle Linux 8, use the appropriate EL8 repository package.

Verify enabled repositories:

sudo dnf repolist enabled | grep mysql

Step 4: Install MySQL Server

Install MySQL Server using DNF.

sudo dnf install mysql-community-server -y

This command installs the MySQL Server package and its required dependencies.

Verify installation with below commands:

systemctl status mysqld

mysql --version

Example output:

mysql Ver 8.4.0 for Linux on x86_64

Step 5: Start and Enable MySQL Service

Start the MySQL service:

sudo systemctl start mysqld

Enable MySQL to start automatically after reboot:

sudo systemctl enable mysqld

Check service status:

sudo systemctl status mysqld

Expected output:

Active: active (running)

Step 6: Retrieve the Temporary Root Password

During installation, MySQL generates a temporary root password.

Retrieve it from the log file:

sudo grep 'temporary password' /var/log/mysqld.log

Example:

A temporary password is generated for root@localhost: Xyz#123Abc

Make a note of this password.

 Step 7: Secure the MySQL Installation

Run the below MySQL security script.

sudo mysql_secure_installation

The script will prompt you to:

Enter temporary root password

Set a new root password

Remove anonymous users

Disable remote root login

Remove test database

Reload privilege tables 

Example interaction:

Securing the MySQL server deployment.

Enter password for user root:

New password:

Re-enter new password:

Remove anonymous users? (Y/N): Y

Disallow root login remotely? (Y/N): Y

Remove test database and access to it? (Y/N): Y

Reload privilege tables now? (Y/N): Y

Step 8: Login to MySQL

Connect to MySQL as root.

mysql -u root -p

Enter the password configured in the previous step.

Verify:

SELECT VERSION();

Show more lines

Example output:

+-----------+

| VERSION() |

+-----------+

| 8.4.0 |

+-----------+

Exit MySQL:

EXIT;

Now What's Next?

Step 9: Create a Database and User

Create a database:

CREATE DATABASE companydb;

Create a dedicated user:

CREATE USER 'dbadmin'@'localhost'

IDENTIFIED BY 'StrongPassword@123';

Grant privileges:

GRANT ALL PRIVILEGES ON companydb.* TO 'dbadmin'@'localhost';

FLUSH PRIVILEGES;

Verify user creation:

SELECT user, host FROM mysql.user;

Step 10: Configure Remote Access (Optional)

If applications need to connect remotely to MySQL, perform the following configuration.

Modify MySQL Configuration

Edit the MySQL configuration file:

sudo vi /etc/my.cnf

Locate:

bind-address=127.0.0.1

Replace with:

bind-address=0.0.0.0

Save and restart MySQL:

sudo systemctl restart mysqld

Now Create Remote User

CREATE USER 'remoteuser'@'%'

IDENTIFIED BY 'StrongPassword@123';

GRANT ALL PRIVILEGES ON companydb.* TO 'remoteuser'@'%';

FLUSH PRIVILEGES;

Make sure to open Firewall Port, allow MySQL traffic through firewall.

sudo firewall-cmd --permanent --add-service=mysql

sudo firewall-cmd --permanent --add-port=3306/tcp

sudo firewall-cmd --reload

Verify:

sudo firewall-cmd --list-services

sudo firewall-cmd --list-ports

Step 11: Verify Connectivity

From any another system having mysql client:

mysql -h <server-ip> -u remoteuser -p

Example:

mysql -h 192.168.1.100 -u remoteuser -p

If successful, you should receive the MySQL prompt:

mysql>

Step 12: Configure Automatic Backups

Create a backup directory:

mkdir -p /backup/mysql

Take a manual backup:

mysqldump -u root -p companydb > /backup/mysql/companydb.sql

Create a cron job:

crontab -e

Add:

0 1 * * * mysqldump -u root -p <YourPassword companydb > /backup/mysql/companydb_$(date +\%F).sql

This backup runs daily at 1:00 AM.

Here, we installed MySQL on Oracle Linux, started the service, secured the root account, and verified the installation.

Best Practices

Use strong passwords for all database accounts.

Avoid using the root account for applications.

Enable regular database backups.

Keep Oracle Linux and MySQL updated with security patches.

Restrict remote access to trusted IP addresses only.

Monitor database logs regularly.

Use SSL/TLS encryption for database connections.


Common Errors:

Service won't start

If the MySQL service fails to start after installation, first check its current status.

sudo systemctl status mysqld

If the service is not running, review the detailed error messages in the MySQL error log.

sudo cat /var/log/mysqld.log

Common causes and solutions

1] Data directory is not initialized

Error: mysqld: Data Dictionary initialization failed

Solution:

sudo mysqld –initialize

or (for insecure initialization)

sudo mysqld --initialize-insecure

Then start the service again.

sudo systemctl start mysqld

2]. Port 3306 is already in use

Check whether another application is using port 3306.

sudo ss -tulnp | grep 3306

If another MySQL instance is running, stop it or change the MySQL port in the configuration file.

3]. Incorrect permissions on the data directory

ls -ld /var/lib/mysql

If required, correct the ownership.

sudo chown -R mysql:mysql /var/lib/mysql

4]. SELinux restrictions (Oracle Linux)

If SELinux is enabled, it may prevent MySQL from accessing required files or directories.

Check the SELinux status.

getenforce

If necessary, review the audit logs or temporarily set SELinux to permissive mode for testing.

sudo setenforce 0

Note: This is intended only for troubleshooting. After identifying the issue, configure the appropriate SELinux policies instead of leaving SELinux in permissive mode.

After resolving the issue, reload the service configuration and start MySQL.

sudo systemctl daemon-reload

sudo systemctl restart mysqld

Verify that the service is running.

sudo systemctl status mysqld

A successful start should show:

Active: active (running)


Temporary root password not found

After installing MySQL, the initial root password is usually generated automatically and stored in the MySQL error log.

sudo grep 'temporary password' /var/log/mysqld.log

Expected output something like:

A temporary password is generated for root@localhost: Abc#1234xyz

If no password is found,

Verify that the MySQL service started successfully

The temporary password is generated only during the initial startup.

If the temporary password cannot be recovered, you can reset the MySQL root password by starting MySQL in safe mode (or with --skip-grant-tables), changing the password, and then restarting the service normally.

Note : Resetting the root password should be used only when the original temporary password is unavailable or has been lost.

For a new installation, the quickest way to retrieve the temporary password is :

sudo grep 'temporary password' /var/log/mysqld.log

If no output is returned, first confirm that MySQL started successfully and that this is truly a fresh installation. In many cases, the absence of a temporary password indicates that the data directory was already initialized or that MySQL was installed using the --initialize-insecure option.


Conclusion

Installing MySQL Server on Oracle Linux is a straightforward process when following the correct steps. By updating the system, installing MySQL packages, securing the installation, configuring users, and enabling backups, you can create a reliable and secure database environment. Proper configuration and regular maintenance will ensure optimal performance and data protection for your applications.


Thanks for reading!

 


Stay tuned with itsdbaworld for upcoming blogs,

- How we can take backups of MySQL Database “

- Restore and Configure MySQL Database from backup

- Clone and Configure MySQL Database from backup on an different Oracle Linux server

- Install and Configure MySQL on an Oracle Linux Server Introduction


No comments:

Post a Comment