Close Menu
    Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»Linux Distributions»CentOS»How to Install MySQL 8.0 on CentOS/RHEL 8

    How to Install MySQL 8.0 on CentOS/RHEL 8

    By RahulOctober 8, 20205 Mins Read

    MySQL is an open-source, relational database management system. At present, it is being developed under the Oracle Corporation. The MySQL 8 is the latest version available for the installation and use of the production application. MySQL 8.0 has many improvements and 2x processing speed over the previous version. In this version, MySQL team includes document store for developing both SQL and NoSQL document applications using a single database.

    This tutorial will help you to install MySQL 8 on CentOS 8 and RHEL 8 systems.

    Prerequisites

    You must have shell access with sudo privileged account on CentOS 8 system.

    Step 1 – Install MySQL

    The MySQL 8 packages are available under the AppStrem repository under CentOS 8. Install the required packages using the following command. This will also install multiple dependent packages.

    sudo dnf -y install @mysql
    

    After completing the installation, enable the MySQL service to auto-start on the system start. Also start service manually for the first time.

    sudo systemctl enable mysqld.service
    sudo systemctl start mysqld.service
    

    Then check the service current status using the following command:

    sudo systemctl status mysqld.service
    
    ● mysqld.service - MySQL 8.0 database server
       Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
       Active: active (running) since Tue 2020-02-25 04:43:13 UTC; 22s ago
     Main PID: 16666 (mysqld)
       Status: "Server is operational"
        Tasks: 39 (limit: 17963)
       Memory: 534.9M
       CGroup: /system.slice/mysqld.service
               └─16666 /usr/libexec/mysqld --basedir=/usr
    
    Feb 25 04:43:04 tecadmin systemd[1]: Starting MySQL 8.0 database server...
    Feb 25 04:43:04 tecadmin mysql-prepare-db-dir[16582]: Initializing MySQL database
    Feb 25 04:43:13 tecadmin systemd[1]: Started MySQL 8.0 database server.
    

    Step 2 – Secure MySQL Installation

    The MySQL installation has been completed. Now you can connect the MySQL server without any password but we recommend to secure the MySQL installation. The MySQL packages provide mysql_secure_installation command to apply the security. Just run the below command on terminal:

    sudo mysql_secure_installation
    

    and follow the on-screen instructions. Below are the details which require user input.

    • Press y|Y for Yes, any other key for No: y
    • Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
    • New password: [ENTER STRONG PASSWORD HERE]
    • Re-enter new password: RE ENTER PASSWORD HERE
    • Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : 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 3 – Connect MySQL

    You have finished the installation and secured the MySQL server. Now connect to MySQL server via console or install phpMyAdmin to use a graphical web interface.

    mysql -u root -p
    
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 10
    Server version: 8.0.17 Source distribution
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql>
    

    Step 4 – Create Database and User

    It’s not recommended to use ‘root’ users to connect databases from applications. So it is a good idea to create a separate user for your application database connection. Below are the commands to create a new MySQL database, then create a new MySQL user and assign privileges on the database.

    You can change the database and user name as per your requirements. Also, use a strong password for the user.

    mysql> CREATE DATABASE tecadmin;
    Query OK, 1 row affected (0.01 sec)
    
    mysql> CREATE USER 'tecadmin'@'localhost' IDENTIFIED BY 'your secure password here';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> GRANT ALL ON tecadmin.* to 'tecadmin'@'localhost';
    Query OK, 0 rows affected (0.00 sec)
    
    mysql> FLUSH PRIVILEGES;
    Query OK, 0 rows affected (0.00 sec)
    

    Now, connect to MySQL server using the newly created user and list available databases.

    mysql -u tecadmin -p
    
    Enter password:
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 11
    Server version: 8.0.17 Source distribution
    
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> SHOW DATABASES;
    +--------------------+
    | Database           |
    +--------------------+
    | information_schema |
    | tecadmin           |
    +--------------------+
    2 rows in set (0.01 sec)
    
    mysql>
    

    Conclusion

    You have successfully installed and configured MySQL 8.0 on CentOS 8 system. Your server is ready for production use. You may also require to configure automated database backup script for the production system.

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

    Related Posts

    Working with Python FastAPI and MySQL

    Resolving MySQL ERROR 1041 (HY000): Out of Memory

    How to Calculate the MySQL Database Size

    Add A Comment

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • How to Change Port in Next.Js
    • Ubuntu 24.04 LTS: The Future of Open-Source Excellence
    • How to Execute Linux Commands in Python
    • Creating MySQL User with GRANT OPTION
    • Where to find crontab (cron) logs in Ubuntu & Debian
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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