Summary: in this tutorial, you will learn step-by-step how to install MySQL 8 on CentOS 7.
To install MySQL 8 on CentOS 7, you follow these steps:
Step 1. Add the MySQL Yum Repository
Add the official MySQL repository to your system’s package manager (yum)
sudo rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
Code language: JavaScript (javascript)
Step 2. Download the official MySQL GPG key using
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql
Code language: JavaScript (javascript)
Step 3. Install MySQL 8 Community Server
Install the MySQL 8 Community Server package using the following command:
sudo yum install mysql-server
Step 4. Start MySQL Service
Start the MySQL service and enable it to run at boot with:
sudo systemctl start mysqld
sudo systemctl enable mysqld
Step 5. Show the default password for the root user
When you install MySQL 8.0, the root user account is granted a temporary password. To show the password of the root user account, you use the following command:
sudo grep 'temporary password' /var/log/mysqld.log | awk '{print $NF}'
Code language: JavaScript (javascript)
Here is the output:
Kq%<ul_0M*O0
Note that your temporary password will be different. You will need this password to change the password of the root
user account.
Step 6. MySQL Secure Installation
Execute the command mysql_secure_installation to secure the MySQL server:
mysql_secure_installation
It will prompt you for the current password of the root account:
Enter password for user root:
Enter the temporary password above and press Enter
. The following message will show:
The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:
Code language: PHP (php)
You will need to enter the new password for the root
‘s account twice. It will prompt some questions, it is recommended to type yes (y):
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Step 7. Connect to MySQL
Use this command to connect to the MySQL server:
mysql -u root -p
It will prompt you for the password of the root
user. You type the password and press Enter
:
Enter password:
It will show the mysql
command:
mysql>
Use the SHOW DATABASES
to display all databases in the current server:
mysql> show databases;
Code language: SQL (Structured Query Language) (sql)
Here is the output:
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.05 sec)
Code language: JavaScript (javascript)
In this tutorial, you have learned step-by-step how to install MySQL 8 on CentOS 7.