Installing and Configuring MySQL 8.0 on CentOS 7

Environment

  • CentOS Linux release 7.5.1804 (Core)
  • MySQL version: mysql80-community-release-el7-1

Pre-installation Check

CentOS 7 ships with MariaDB by default. Verify weather MySQL is already installed:

rpm -qa | grep mysql
[admin@localhost ~]$ rpm -qa | grep mysql
[admin@localhost ~]$ 

An empty result indicates no MySQL packages are present.

Installing the MySQL Repository

Navigate to the local source directory:

cd /usr/local/src

Download the MySQL 8.0 RPM repository (MySQL 8.0 offers approximately 2x performance improvement over version 5.7):

wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

Install the RPM package:

rpm -ivh mysql80-community-release-el7-1.noarch.rpm

Installing MySQL Server

Install the MySQL server package using yum:

yum install -y mysql-community-server

Starting the MySQL Service

systemctl start mysqld

Enabling Automatic Startup

Configure MySQL to start automatically on system boot:

systemctl enable mysqld

Retrieving the Initial Root Password

MySQL generates a temporary root password during installlation, stored in /var/log/mysqld.log. Locate it with:

cat /var/log/mysqld.log | grep temporary
[admin@localhost ~]$ cat /var/log/mysqld.log | grep temporary
[admin@localhost ~]$ 2018-08-28T14:51:41.543460Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: K9xnmP:QBv#2

The initial password is: K9xnmP:QBv#2

Connect to the database:

mysql -u root -p

Changing the Root Password

After logging in, attempting any operation results in:

mysql> use mysql;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

Reset the password using ALTER USER:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPass123!';

Alternative syntax:

SET PASSWORD FOR 'root'@'localhost' = PASSWORD('NewPass123!');

Note: MySQL 8.0 includes the validate_password plugin enabled by default. Passwords must contain at least 8 characters including uppercase, lowercase, numbers, and special characters. Violations result in ERROR 1819.

Viewing Password Policy Settings

SHOW VARIABLES LIKE '%password%';
mysql> SHOW VARIABLES LIKE '%password%';
+----------------------------------------------+-----------------+
| Variable_name                                | Value           |
+----------------------------------------------+-----------------+
| caching_sha2_password_auto_generate_rsa_keys | ON              |
| caching_sha2_password_private_key_path       | private_key.pem |
| caching_sha2_password_public_key_path        | public_key.pem  |
| default_password_lifetime                    | 0               |
| disconnect_on_expired_password               | ON              |
| mysql_native_password_proxy_users            | OFF             |
| password_history                             | 0               |
| password_reuse_interval                      | 0               |
| report_password                              |                 |
| sha256_password_auto_generate_rsa_keys       | ON              |
| sha256_password_private_key_path             | private_key.pem |
| sha256_password_public_key_path              | public_key.pem  |
| validate_password.check_user_name            | ON              |
| validate_password.dictionary_file            |                 |
| validate_password.length                     | 8               |
| validate_password.mixed_case_count           | 1               |
| validate_password.number_count               | 1               |
| validate_password.policy                     | MEDIUM          |
| validate_password.special_char_count         | 1               |
+----------------------------------------------+-----------------+
20 rows in set (0.01 sec)

Key parameters under MEDIUM policy:

Parameter Description
validate_password.length Minimum password length
validate_password.mixed_case_count Minimum uppercase/lowercase characters
validate_password.number_count Minimum digits required
validate_password.special_char_count Minimum special characters
validate_password.policy Policy level (LOW/MEDIUM/STRONG)

Available password policies:

Policy Level Requirements
0 or LOW Length only
1 or MEDIUM Length plus numeric, mixed case, and special characters
2 or STRONG Length plus mixed case, special characters, and dictionary file

Reference: MySQL Documentation

Adjusting Password Policy

Edit /etc/my.cnf to modify passowrd policy. Options include:

[mysqld]
validate_password.policy=0

Or disable password validation entirely:

[mysqld]
validate_password=off

Apply changes:

systemctl restart mysqld

Creating Remote Access Users

By default, only local connections are permitted. For remote access, either modify the root user or create a dedicated account:

GRANT ALL PRIVILEGES ON *.* TO 'adminuser'@'%' IDENTIFIED BY 'SecureP@ssw0rd!' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Configuring UTF-8 Encoding

Update /etc/my.cnf under the [mysqld] section:

[mysqld]
character_set_server=utf8
init_connect='SET NAMES utf8'

datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock

log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Restart the service:

systemctl restart mysqld

Verify character set settings:

SHOW VARIABLES LIKE '%character%';
mysql> SHOW VARIABLES LIKE '%character%';
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb4                        |
| character_set_connection | utf8mb4                        |
| character_set_database   | utf8                           |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb4                        |
| character_set_server     | utf8                           |
| character_set_system     | utf8                           |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+
8 rows in set (0.01 sec)

Default File Locations

Purpose Path
Configuration /etc/my.cnf
Error Log /var/log/mysqld.log
Service Script /usr/lib/systemd/system/mysqld.service
Socket File /var/run/mysqld/mysqld.pid
Data Directory /var/lib/mysql

Tags: centos MySQL 8.0 installation Database Configuration Linux

Posted on Thu, 16 Jul 2026 16:49:59 +0000 by Chiaki