Installing MySQL 5.7 on CentOS 7 via Yum Repository

Removing Existing Database Packages

CentOS 7 typically ships with MariaDB as the default database, which conflicts with MySQL. Before installation, check for and remove any existing MySQL or MariaDB installations.

rpm -qa | grep -E 'mysql|mariadb'

If MariaDB libraries are present, remove them. Note that dependent packages like postfix might block this removal; remove them first if necessary.

yum remove postfix -y
yum remove mariadb-libs -y
rm -rf /var/lib/mysql

Configuring the Yum Repository

Navigate to a working directory and download the official MySQL Yum repository RPM package.

cd /usr/local/src
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

Install the repository definition to enable yum to locate MySQL packages.

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

Installing MySQL Server

Proceed to install the MySQL community server.

yum install mysql-community-server -y

If the installation halts due to GPG key verification failures, import the updated key from the MySQL official site.

rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
yum install mysql-community-server -y

Initializing and Starting the Service

Initialize the MySQL data directory and ensure the correct file ownership is set.

mysqld --initialize
chown -R mysql:mysql /var/lib/mysql

Start the mysqld service and verify it is running correctly.

systemctl start mysqld
systemctl status mysqld

Securing the Root Account

MySQL 5.7 generates a temporary password for the root user during initialization. Retrieve this password from the log file.

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

Log in to the MySQL client using the retrieved password.

mysql -u root -p

Update the root password immediately. The default security policy requires a strong password containing uppercase, lowercase, numbers, and special characters.

ALTER USER 'root'@'localhost' IDENTIFIED BY 'New_Strong_Password_123';

Configuring Remote Access

To enable remote connections for the root user, switch to the system database and update the host permissions.

USE mysql;
UPDATE user SET Host='%' WHERE User='root' AND Host='localhost';
FLUSH PRIVILEGES;

Adjust the firewall settings to allow incoming traffic on the default MySQL port.

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

Finally, enable the MySQL service to start automatically on system boot.

systemctl enable mysqld

Tags: MySQL centos Database Administration Linux RDBMS

Posted on Sat, 29 Aug 2026 16:36:31 +0000 by smoothrider