Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    You are at:Home»General Articles»How To Install MySQL 8.0 on CentOS 7/6

    How To Install MySQL 8.0 on CentOS 7/6

    By RahulJune 17, 20213 Mins Read

    MySQL 8 is the latest version available for the installation. MySQL is the 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 LInux using the package manager.

    Advertisement

    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
    

    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.

    database MySQL MySQL 8 MySQL 8.0
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    Implementing a Linux Server Security Audit: Best Practices and Tools

    15 Practical Examples of dd Command in Linux

    Iptables: Common Firewall Rules and Commands

    View 10 Comments

    10 Comments

    1. Pradeesh on August 31, 2021 9:34 am

      Excellent. Thank you very much. God bless you for sharing the knowledge.

      Reply
    2. Simon on January 8, 2021 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.

      Reply
    3. JH on July 4, 2020 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

      Reply
    4. izak on November 14, 2019 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.

      Reply
      • Simon on January 8, 2021 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.

        Reply
    5. Junaid Khan on November 14, 2019 7:00 am

      Thanks, Very clear and step by step doc…

      Reply
    6. Satinder SINGH on September 28, 2019 5:59 pm

      Thanks my friend. Very neat article.

      Reply
    7. Akila on September 25, 2019 9:50 am

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

      Reply
    8. Bom Proapps on September 22, 2019 4:21 am

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

      Reply
    9. PEDRO LÓPEZ on July 19, 2019 2:47 am

      Thank you very much. Very useful tutorial well explained.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.