How To Install MySQL 8.0 On CentOS, RHEL and Fedora

MySQL is an open source relational database management system (DBMS) which is much of the time conveyed in a wide grouping of settings. Most every now and again it is conveyed as a feature of the LAMP Stack. The database system is additionally simple to utilize and exceedingly convenient and is, with regards to numerous applications, amazingly productive

In this article I will describe how to install MySQL server on CentOS RHEL and Fedora.

Install and Configure MySQL Yum Repository

First of all you will need to enable MySQL yum repository on your system, typing below command:

On CentOS/RHEL 7 system

# rpm -Uvh

On CentOS/RHEL 6 system

# rpm -Uvh

On Fedora 26 system

# rpm -Uvh

On Fedora 25 system

# rpm -Uvh

On Fedora 24 system

# rpm -Uvh

Install MySQL 8.0 Community Server

After adding and enabling yum repository on your system, now install MySQL server:

# yum --enablerepo=mysql80-community install mysql-community-server     ## CentOS, RHEL 7 
# dnf --enablerepo=mysql80-community install mysql-community-server     ## Fedora 26/25/24

Grep MySQL Root Password

After installing MySQL 8.0 you will get a temporary password for MySQL root user. You can find the temporary password in its logs file.

# grep "A temporary password" /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: hosygMikj1+t636

Start MySQL Service

Now start MySQL service typing below command:

# service mysqld start
# systemctl start mysqld.service

MySQL Post Installation Setup

If you are installing MySQL first time type the below command to secure MySQL server.

# mysql_secure_installation

New password:

Re-enter new password:
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
Using existing password for root.

Estimated strength of the password: 100
Change the password for root ? ((Press y|Y for Yes, any other key for No) : No

 ... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y

Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y

By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...

 - Removing privileges on test database...

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

All done!

Restart MySQL service

After securing MySQL server now restart the MySQL service using below command;

# service mysqld restart
# systemctl restart mysqld.service

Enable service to start automatically during system reboot:

# chkconfig mysqld on
# systemctl enable mysqld.service

Connect MySQL Server Using MySQL Client

Now connect MySQL database server using MySQL client:

# mysql -h localhost -u root -p 

Type your password here..

Run the following command to create new database, create a user and assign privileges to the user on the database.

mysql> CREATE DATABASE testdb;
mysql> CREATE USER 'dbuser'@'%' IDENTIFIED BY 'password';
mysql> GRANT ALL ON testdb.* TO 'dbuser'@'%';


You have successfully installed MySQL server on your system.


Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at LookLinux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

1 Comment

  • Thank you team for the article on mysql installation, Is there a way to change the default installation directory to a new location while trying to install the software. I have created a new mount only for mysql and if I need to have the everything installed and pointed to the new disk while installation what I need to do.? Thank You in advance.

Leave a Comment