Inspect the system for pre-existing MySQL or MariaDB installations to avoid package conflicts.
rpm -qa | grep -i mariadb
# Remove identified packages if present
sudo rpm -e --nodeps <package_name>
Configure the official MySQL Yum repository by downloading the release package. Using curl is an alternative to wget for fetching resources.
curl -LO https://repo.mysql.com/mysql80-community-release-el7-9.noarch.rpm
Install the repository configuration to enable the necessary software channels.
sudo yum localinstall -y mysql80-community-release-el7-9.noarch.rpm
Deploy the database server component. If the system uses AppStream modules, disable the default mysql stream to prevent version mismatches.
sudo yum module disable -y mysql
sudo yum install -y mysql-community-server
Handle potential GPG key verification errors by importing the updated key or bypassing the check during the initial setup.
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
# Fallback if key issues persist
sudo yum install -y mysql-community-server --nogpgcheck
Initialize the service and retrieve the autogenerated tempporary root password from the logs.
sudo systemctl start mysqld
sudo grep 'temporary password' /var/log/mysqld.log
Connect to the database instance using the temporary credentials and enforce a new secure password.
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'StrongPass123!';
MySQL 8.0 implements stricter validation rules compared to version 5.7. Adjust the policy level if the chosen password is rejected.
-- Inspect current validation settings
SHOW VARIABLES LIKE 'validate_password%';
-- Relax policy requirements globally
SET GLOBAL validate_password.policy = LOW;
Enable remote connectivity for the root account by modifying the host entry in the system table.
USE mysql;
UPDATE user SET Host = '%' WHERE User = 'root';
FLUSH PRIVILEGES;
For routine operations, provision dedicated users with scoped privileges rather than using root remotely. Note that MySQL 8.0 requires separate statements for user creation and granting permissions.
CREATE USER 'dev_admin'@'%' IDENTIFIED BY 'SecurePass456!';
GRANT ALL PRIVILEGES ON project_db.* TO 'dev_admin'@'%';
FLUSH PRIVILEGES;
Configure the system firewall to allow inbound traffic on the default database port.
sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp
sudo firewall-cmd --reload
Cloud hosting environments often require additional security group rules to expose port 3306 externally.
Modify the character set configuration by editing the main configuraton file. Ensure the service is stopped before making changes.
sudo systemctl stop mysqld
sudo vim /etc/my.cnf
Append the following settings to enforce UTF-8 encoding across client and server connections.
[client]
default-character-set = utf8mb4
[mysqld]
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
Restart the daemon to apply the configuraton updates and verify the operational status.
sudo systemctl start mysqld
mysql -u root -p -e "STATUS;"
Register the service to launch automatically during system boot.
sudo systemctl enable mysqld