• Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us
TecAdmin
Menu
  • Home
  • Ubuntu 18.04
    • Whats New?
    • Upgrade Ubuntu
    • Install Java
    • Install Node.js
    • Install Docker
    • Install Git
    • Install LAMP Stack
  • Tutorials
    • AWS
    • Shell Scripting
    • Docker
    • Git
    • MongoDB
  • Funny Tools
  • FeedBack
  • Submit Article
  • About Us

How To Install MySQL 8.0 on CentOS 7/6 & Fedora 31/30

Written by Rahul, Updated on February 26, 2020

MySQL 8 is the latest version available for the installation. MySQL is a most popular database server for Linux systems, it also supports a large number of platforms. This tutorial will help you to Install MySQL Server 8.0 Community Edition on CentOS/RHEL 7/6, Fedora 31/30/29/28 using the package manager.

Step 1 – Setup Yum Repository

First, you need to enable MySQL yum repository in your system provided by MySQL. Execute one of the below commands as per your operating system version.

### On CentOS/RHEL 7 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm

### On CentOS/RHEL 6 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-el6-3.noarch.rpm

### On Fedora 31 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-fc31-1.noarch.rpm

### On Fedora 30 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-fc30-1.noarch.rpm

### On Fedora 29 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-fc29-2.noarch.rpm

### On Fedora 28 system ###
rpm -Uvh https://repo.mysql.com/mysql80-community-release-fc28-2.noarch.rpm

Step 2 – Install MySQL Community Server

The MySQL yum repository contains multiple repositories configuration for multiple MySQL versions. So first disable all repositories in mysql repo file.

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

Then execute one of the followings commands as per your operating system to install MySQL.

yum --enablerepo=mysql80-community install mysql-community-server  ## CentOS & RedHat 
dnf --enablerepo=mysql80-community install mysql-community-server  ## Fedora Systems 

Step 3 – Start MySQL Service

Start the MySQL server using the following command from the Linux terminal.

Using SysVinit

service mysqld start

Using Systemd

systemctl start mysqld.service

Step 4 – Find default root Password

With the installation of MySQL 8.0, a temporary password is created for the MySQL root user. You can find the temporary password generated in log files.

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

Output:

[Note] [MY-010454] [Server] A temporary password is generated for [email protected]: VWa>Bo9xFUrs

Step 5 – MySQL Post Install Setup

After installing MySQL first time, execute mysql_secure_installation command to secure MySQL server. It will prompt for few question’s, we recommended to say yes ( y ) for each.

mysql_secure_installation
Enter password for user root:

The existing password for the user account root has expired. Please set a new password.

New password:
Re-enter new password:

Change the password for root ? ((Press y|Y for Yes, any other key for No) : n

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 MySQL Service

The MySQL installation has been successfully completed. Now restart the service and set up autostart on system bootup.

### Using SysVinit
service mysqld restart
chkconfig mysqld on

### Using Systemd
systemctl restart mysqld.service
systemctl enable mysqld.service

Step 7 – Working with MySQL

Now connect mysql database server Linux shell using below command. It will prompt for the password for authentication. On successful login, you will get the MySQL command prompt, where we can execute SQL queries.

mysql -h localhost -u root -p

Install MySQL 8 on CentOS & Fedora

After login, You can use the following commands to create a new database, create a user and assign privileges to the user on the database. Change values as per your requirements.

1
2
3
4
5
6
7
8
9
10
11
### CREATE DATABASE
mysql> CREATE DATABASE mydb;
 
### CREATE USER ACCOUNT
mysql> CREATE USER 'dbuser'@'192.168.10.101' IDENTIFIED BY 'secret';
 
### GRANT PERMISSIONS ON DATABASE
mysql> GRANT ALL ON mydb.* TO 'dbuser'@'192.168.10.101';
 
###  RELOAD PRIVILEGES
mysql> FLUSH PRIVILEGES;

Congratulations! you have successfully installed MySQL server on your system. Use below quick links for basic MySQL tasks.

Share it!
Share on Facebook
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on Tumblr
Share on Whatsapp
Rahul
Rahul
Connect on Facebook Connect on Twitter

I, Rahul Kumar am the founder and chief editor of TecAdmin.net. I am a Red Hat Certified Engineer (RHCE) and working as an IT professional since 2009..

9 Comments

  1. Avatar Simon Reply
    January 8, 2021 at 7:19 pm

    Thank you for clearing the process up. I have been working on this install for two days. The information that I found was useless.

    I ran a search, saw the TecAdmin link, which I recognized from previous issues opened the link and 10 minutes later I have a running server and documented install. You make me look good!

    With all the confusion around MariaDB/MySQL and CentOS changing hands, it is tedious trying to keep up with all the changes, I need to be producing not floundering. I did not find any mention of the Community repo before this article. I looked too. Reading package notes, and then the MariaDB website, (a big wabbit hole) there was never any mention of the community repo. NONE!

    In the future I will look to here first.

    Thank you.

  2. Avatar JH Reply
    July 4, 2020 at 4:18 pm

    Hi, I’m kinda new in this… by the way I need help, what is the password for user root in step 5?, I put the one from the begining of my fedora installation and i tried with the one generated in step 4, both send me an error: access denied for user root…….
    Apreciate all your effort, thank you

  3. Avatar izak Reply
    November 14, 2019 at 7:44 am

    Hello,
    thanks for this valuable post.
    I have a question if you or another user can answer it.
    Why in mysql 8 the OS user mysql is disabled ? I mean by disabled, we cannot connect to because the shell in /etc/passwd is set to /bin/false ?
    It means that for managing mysql service, we will always need to log as root which goes in contradiction with our needs to separate roles.

    Any explanation please?
    Thanks again for the quality of the post.

    • Avatar Simon Reply
      January 8, 2021 at 7:24 pm

      You can still login as mysql. I had the same problem with Apache. Use this syntax:

      su -s /bin/bash mysql

      It will log you in, no spiffy environment settings, useful in so many ways like checking permissions and what not.

  4. Avatar Junaid Khan Reply
    November 14, 2019 at 7:00 am

    Thanks, Very clear and step by step doc…

  5. Avatar Satinder SINGH Reply
    September 28, 2019 at 5:59 pm

    Thanks my friend. Very neat article.

  6. Avatar Akila Reply
    September 25, 2019 at 9:50 am

    Very Good. It is very hard to find proper installation documentation guides these days. Your document is very clear and straightforward.

  7. Avatar Bom Proapps Reply
    September 22, 2019 at 4:21 am

    Awesome! Thank you so much. You save too much time for me.

  8. Avatar PEDRO LÓPEZ Reply
    July 19, 2019 at 2:47 am

    Thank you very much. Very useful tutorial well explained.

Leave a Reply Cancel reply

Popular Posts

  • How To Install Python 3.9 on Ubuntu 20.04 5
  • How To Install Python 3.9 on Ubuntu 18.04 0
  • How to Use AppImage on Linux (Beginner Guide) 2
  • How to Install Python 3.9 on CentOS/RHEL 7 & Fedora 32/31 0
  • How To Install VNC Server on Ubuntu 20.04 1
© 2013-2020 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy