Install MySQL CentOS

To install MySQL 8 on CentOS 7, you follow these steps:

Step 1. Setup Yum repository

Execute the following command to enable MySQL yum repository on CentOS:

rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

Step 2. Install MySQL 8 Community Server

Since the MySQL yum repository has multiple repositories configuration for multiple MySQL versions, you need to disable all repositories in mysql repo file:

sed -i 's/enabled=1/enabled=0/' /etc/yum.repos.d/mysql-community.repo

And execute the following command to install MySQL 8:

yum --enablerepo=mysql80-community install mysql-community-server

Step 3. Start MySQL Service

Use this command to start mysql service:

service mysqld start

Step 4. Show the default password for 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 this command:

grep "A temporary password" /var/log/mysqld.log

Here is the output:

[Note] A temporary password is generated for root@localhost: hjkygMukj5+t783

Note that your temporary password will be different. You will need this password for changing the password of the root user account.

Step 5. MySQL Secure Installation

Execute the command mysql_secure_installation to secure 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:

You will need to enter the new password for the root‘s account twice. It will prompt for 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 6. Restart and enable the MySQL service

Use the following command to restart the mysql service:

service mysqld restart

and autostart mysql service on system’s startup:

chkconfig mysqld on

Step 7. Connect to MySQL

Use this command to connect to 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:
mysql>

Use the SHOW DATABASES to display all databases in the current server:

mysql> show databases;

Here is the output:

+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.05 sec)

 

  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

Install MySQL

Note that if you use other operating system platforms such as Linux and macOS, you use the following tutorial: Install MySQL 8 on CentOS 7 Install MySQL 8 on Ubuntu Download MySQL Installer...

Install MySQL on Ubuntu

  Step 1. Update package index Execute the following command to update the local packages index with the latest changes made in the repositories: sudo apt update Step 2. Upgrade packages Type...

How to Load the Sample Database into MySQL Server

Step 1 Download the classicmodels database from the MySQL sample database section. Step 2 Unzip the downloaded file into a temporary folder. You can use any folder you want. To make it simple,...

MySQL Sample Database

We use the classicmodels database as a MySQL sample database to help you work with MySQL quickly and effectively. The classicmodels database is a retailer of scale models of classic cars database....