MySQL is a free database management System software most commonly used in three-tier applications to store and retrieve records and information.
MySQL was initially developed by MYSQL AB, now owned by Oracle Corporation. It was the primary database application on Linux until MariaDB, a fork of MySQL, came into the picture.
In this article, we will see go through steps on how to install MySQL 8.0 on CentOS 8 / RHEL 8.
Install MySQL 8.0 On CentOS 8 / RHEL 8
Contents
1. Install MySQL 8.0 from MySQL Dev Community
Add the official repository of MySQL to install the MySQL community server.
rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
Make sure the MySQL repository has been added and enabled by using the following command.
yum repolist all | grep mysql | grep enabled
Output:
Last metadata expiration check: 0:00:07 ago on Wed 09 Oct 2019 03:03:04 PM UTC. mysql-connectors-community MySQL Connectors Community enabled: 14 mysql-tools-community MySQL Tools Community enabled: 5 mysql80-community MySQL 8.0 Community Server enabled: 11
Use the yum command in CentOS/RHEL to install the latest stable version of MySQL. Disable AppStream repository temporarily to install MySQL from MySQL Dev Community.
### CentOS 8 ### yum --disablerepo=AppStream install -y mysql-community-server ### RHEL 8 ### yum --disablerepo=rhel-8-for-x86_64-appstream-rpms install -y mysql-community-server
Output:
Last metadata expiration check: 0:01:03 ago on Fri 11 Oct 2019 03:03:04 PM UTC. Dependencies resolved. =================================================================================================================== Package Arch Version Repository Size =================================================================================================================== Installing: mysql-community-server x86_64 8.0.17-1.el8 mysql80-community 50 M Installing dependencies: libaio x86_64 0.3.110-12.el8 BaseOS 32 k numactl-libs x86_64 2.0.12-2.el8 BaseOS 36 k perl-Carp noarch 1.42-396.el8 BaseOS 30 k perl-Encode x86_64 4:2.97-3.el8 BaseOS 1.5 M perl-Errno x86_64 1.28-416.el8 BaseOS 76 k perl-Exporter noarch 5.72-396.el8 BaseOS 34 k perl-File-Path noarch 2.15-2.el8 BaseOS 38 k . . . . . . (35/38): mysql-community-common-8.0.17-1.el8.x86_64.rpm 953 kB/s | 592 kB 00:00 (36/38): mysql-community-libs-8.0.17-1.el8.x86_64.rpm 1.5 MB/s | 1.3 MB 00:00 (37/38): mysql-community-client-8.0.17-1.el8.x86_64.rpm 5.5 MB/s | 11 MB 00:01 (38/38): mysql-community-server-8.0.17-1.el8.x86_64.rpm 7.3 MB/s | 50 MB 00:06 ------------------------------------------------------------------------------------------------------------------- Total 6.7 MB/s | 74 MB 00:10 warning: /var/cache/dnf/mysql80-community-b1f1ed5ba88ce0f8/packages/mysql-community-client-8.0.17-1.el8.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY MySQL 8.0 Community Server 27 MB/s | 27 kB 00:00 Importing GPG key 0x5072E1F5: Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>" Fingerprint: A4A9 4068 76FC BD3C 4567 70C8 8C71 8D3B 5072 E1F5 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql Key imported successfully Running transaction check Transaction check succeeded. Running transaction test Transaction test succeeded. Running transaction Preparing : 1/1 Installing : perl-Exporter-5.72-396.el8.noarch 1/38 Installing : perl-libs-4:5.26.3-416.el8.x86_64 2/38 Installing : perl-Carp-1.42-396.el8.noarch 3/38 Installing : perl-parent-1:0.237-1.el8.noarch 4/38 . . . . . . Installed: mysql-community-server-8.0.17-1.el8.x86_64 libaio-0.3.110-12.el8.x86_64 numactl-libs-2.0.12-2.el8.x86_64 perl-Carp-1.42-396.el8.noarch perl-Encode-4:2.97-3.el8.x86_64 perl-Errno-1.28-416.el8.x86_64 perl-Exporter-5.72-396.el8.noarch perl-File-Path-2.15-2.el8.noarch perl-File-Temp-0.230.600-1.el8.noarch perl-Getopt-Long-1:2.50-4.el8.noarch perl-HTTP-Tiny-0.074-1.el8.noarch perl-IO-1.38-416.el8.x86_64 perl-MIME-Base64-3.15-396.el8.x86_64 perl-PathTools-3.74-1.el8.x86_64 perl-Pod-Escapes-1:1.07-395.el8.noarch perl-Pod-Perldoc-3.28-396.el8.noarch perl-Pod-Simple-1:3.35-395.el8.noarch perl-Pod-Usage-4:1.69-395.el8.noarch perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 perl-Socket-4:2.027-2.el8.x86_64 perl-Storable-1:3.11-3.el8.x86_64 perl-Term-ANSIColor-4.06-396.el8.noarch perl-Term-Cap-1.17-395.el8.noarch perl-Text-ParseWords-3.30-395.el8.noarch perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch perl-Time-Local-1:1.280-1.el8.noarch perl-Unicode-Normalize-1.25-396.el8.x86_64 perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-416.el8.x86_64 perl-libs-4:5.26.3-416.el8.x86_64 perl-macros-4:5.26.3-416.el8.x86_64 perl-parent-1:0.237-1.el8.noarch perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64 mysql-community-client-8.0.17-1.el8.x86_64 mysql-community-common-8.0.17-1.el8.x86_64 mysql-community-libs-8.0.17-1.el8.x86_64 Complete!
2. Install MySQL 8.0 from AppStream
MySQL is now available through the Application Stream (Red Hat Enterprise Linux 8 for x86_64 – AppStream (RPMs)) for RHEL 8 and CentOS 8. So, you would not need to add an official repository of MySQL to install MySQL server on RHEL 8.
Check if the AppStream repository is enabled on RHEL 8 using the following command.
subscription-manager repos --list-enabled
Output:
+----------------------------------------------------------+ Available Repositories in /etc/yum.repos.d/redhat.repo
+----------------------------------------------------------+
Repo ID: rhel-8-for-x86_64-baseos-rpms
Repo Name: Red Hat Enterprise Linux 8 for x86_64 - BaseOS (RPMs)
Repo URL: https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/baseos/os
Enabled: 1 Repo ID: rhel-8-for-x86_64-appstream-rpms
Repo Name: Red Hat Enterprise Linux 8 for x86_64 - AppStream (RPMs)
Repo URL: https://cdn.redhat.com/content/dist/rhel8/$releasever/x86_64/appstream/os
Enabled: 1
Use yum command to install the latest version of MySQL.
yum -y install @mysql
Output:
Last metadata expiration check: 0:01:25 ago on Fri 11 Oct 2019 03:35:47 PM UTC. Dependencies resolved. =================================================================================================================== Package Arch Version Repository Size =================================================================================================================== Installing group/module packages: mysql-server x86_64 8.0.13-1.module_el8.0.0+41+ca30bab6 AppStream 25 M Installing dependencies: mariadb-connector-c-config noarch 3.0.7-1.el8 AppStream 13 k mecab x86_64 0.996-1.module_el8.0.0+41+ca30bab6.9 AppStream 397 k mysql x86_64 8.0.13-1.module_el8.0.0+41+ca30bab6 AppStream 9.2 M mysql-common x86_64 8.0.13-1.module_el8.0.0+41+ca30bab6 AppStream 142 k mysql-errmsg x86_64 8.0.13-1.module_el8.0.0+41+ca30bab6 AppStream 523 k perl-Digest noarch 1.17-395.el8 AppStream 27 k perl-Digest-MD5 x86_64 2.55-396.el8 AppStream 37 k perl-Net-SSLeay x86_64 1.85-6.el8 AppStream 358 k perl-URI noarch 1.73-3.el8 AppStream 116 k . . . . . . Enabling module streams: mysql 8.0 Transaction Summary =================================================================================================================== Install 51 Packages Total download size: 48 M Installed size: 278 M Downloading Packages: (1/51): mariadb-connector-c-config-3.0.7-1.el8.noarch.rpm 12 kB/s | 13 kB 00:01 (2/51): mysql-common-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm 1.3 MB/s | 142 kB 00:00 (3/51): mecab-0.996-1.module_el8.0.0+41+ca30bab6.9.x86_64.rpm 328 kB/s | 397 kB 00:01 (4/51): mysql-errmsg-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm 5.7 MB/s | 523 kB 00:00 (5/51): perl-Digest-1.17-395.el8.noarch.rpm 530 kB/s | 27 kB 00:00 (6/51): perl-Digest-MD5-2.55-396.el8.x86_64.rpm 959 kB/s | 37 kB 00:00 (7/51): mysql-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64.rpm 6.3 MB/s | 9.2 MB 00:01 . . . . . . Transaction test succeeded. Running transaction Preparing : 1/1 Installing : perl-Exporter-5.72-396.el8.noarch 1/51 Installing : perl-libs-4:5.26.3-416.el8.x86_64 2/51 Installing : perl-Carp-1.42-396.el8.noarch 3/51 Installing : perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 4/51 Installing : perl-parent-1:0.237-1.el8.noarch 5/51 . . . . . . Installed: mysql-server-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64 perl-IO-Socket-IP-0.39-5.el8.noarch perl-IO-Socket-SSL-2.060-2.el8.noarch perl-Mozilla-CA-20160104-7.el8.noarch mariadb-connector-c-config-3.0.7-1.el8.noarch mecab-0.996-1.module_el8.0.0+41+ca30bab6.9.x86_64 mysql-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64 mysql-common-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64 mysql-errmsg-8.0.13-1.module_el8.0.0+41+ca30bab6.x86_64 perl-Digest-1.17-395.el8.noarch perl-Digest-MD5-2.55-396.el8.x86_64 perl-Net-SSLeay-1.85-6.el8.x86_64 perl-URI-1.73-3.el8.noarch perl-libnet-3.11-3.el8.noarch protobuf-lite-3.5.0-7.el8.x86_64 libaio-0.3.110-12.el8.x86_64 numactl-libs-2.0.12-2.el8.x86_64 perl-Carp-1.42-396.el8.noarch perl-Data-Dumper-2.167-399.el8.x86_64 perl-Encode-4:2.97-3.el8.x86_64 perl-Errno-1.28-416.el8.x86_64 perl-Exporter-5.72-396.el8.noarch perl-File-Path-2.15-2.el8.noarch perl-File-Temp-0.230.600-1.el8.noarch perl-Getopt-Long-1:2.50-4.el8.noarch perl-HTTP-Tiny-0.074-1.el8.noarch perl-IO-1.38-416.el8.x86_64 perl-MIME-Base64-3.15-396.el8.x86_64 perl-PathTools-3.74-1.el8.x86_64 perl-Pod-Escapes-1:1.07-395.el8.noarch perl-Pod-Perldoc-3.28-396.el8.noarch perl-Pod-Simple-1:3.35-395.el8.noarch perl-Pod-Usage-4:1.69-395.el8.noarch perl-Scalar-List-Utils-3:1.49-2.el8.x86_64 perl-Socket-4:2.027-2.el8.x86_64 perl-Storable-1:3.11-3.el8.x86_64 perl-Term-ANSIColor-4.06-396.el8.noarch perl-Term-Cap-1.17-395.el8.noarch perl-Text-ParseWords-3.30-395.el8.noarch perl-Text-Tabs+Wrap-2013.0523-395.el8.noarch perl-Time-Local-1:1.280-1.el8.noarch perl-Unicode-Normalize-1.25-396.el8.x86_64 perl-constant-1.33-396.el8.noarch perl-interpreter-4:5.26.3-416.el8.x86_64 perl-libs-4:5.26.3-416.el8.x86_64 perl-macros-4:5.26.3-416.el8.x86_64 perl-parent-1:0.237-1.el8.noarch perl-podlators-4.11-1.el8.noarch perl-threads-1:2.21-2.el8.x86_64 perl-threads-shared-1.58-2.el8.x86_64 policycoreutils-python-utils-2.8-16.1.el8.noarch Complete!
Manage MySQL server Service
After the installation of MySQL, start MySQL server service using the following command.
systemctl start mysqld
Enable MySQL server at system startup.
systemctl enable mysqld
Verify that MySQL server is started using the following command.
systemctl status mysqld
Output:
● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2019-10-11 06:07:35 UTC; 1min 59s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 4633 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 4708 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 9584) Memory: 496.4M CGroup: /system.slice/mysqld.service └─4708 /usr/sbin/mysqld Oct 11 06:07:23 centos8 systemd[1]: Starting MySQL Server... Oct 11 06:07:35 centos8 systemd[1]: Started MySQL Server.
Secure MySQL server
Installed MySQL from MySQL Dev Community
In CentOS 8 / RHEL 8, the initial MySQL root password can be found in /var/log/mysqld.log. You can use the below command to take the password from the log file.
cat /var/log/mysqld.log | grep -i 'temporary password'
Output:
2019-10-11T06:07:30.167664Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: tbZU*wBV0cAV
Now, you need to run mysql_secure_installation to secure your MySQL installation. This command takes care of setting the root password, removing anonymous users, disallow root login remotely, etc.
mysql_secure_installation
Output:
Securing the MySQL server deployment. Enter password for user root: << Enter the temporary password you got from the previous step The existing password for the user account root has expired. Please set a new password. New password: << Enter new root password Re-enter new password: << Re-enter new root password The 'validate_password' component is installed on the server. The subsequent steps will run with the existing configuration of the component. 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) : N << Type N and Enter as we have already set root password ... 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 environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y << Remove anonymous user Success. 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 << Disallow root login remotely Success. 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 environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y << Remove test database - Dropping test database... Success. - Removing privileges on test database... Success. 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 << Reload privilege tables Success. All done!
Installed MySQL from AppStream
In CentOS 8 / RHEL 8, no password is set for MySQL root user. So, we will run mysql_secure_installation to secure your MySQL installation by setting the root password, removing anonymous users, disallow root login remotely, etc.
mysql_secure_installation
Output:
Securing the MySQL server deployment. Connecting to MySQL using a blank password. VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component? Press y|Y for Yes, any other key for No: Y << Type Y to use VALIDATE PASSWORD COMPONENT to check strength of passwords There are three levels of password validation policy: LOW Length >= 8 MEDIUM Length >= 8, numeric, mixed case, and special characters STRONG Length >= 8, numeric, mixed case, special characters and dictionary file Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 1 << Choose the Level of Strongness Please set the password for root here. New password: << Enter Root Password Re-enter new password: << Re-enter Root Password Estimated strength of the password: 100 Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y << Press Y to set password 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 environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y << Press Y to Remove Anonymous User Success. 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 << Press Y to Disallow Remote Root Login Success. 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 environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y << Press Y to Remove test database - Dropping test database... Success. - Removing privileges on test database... Success. 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 << Press Y to Reload Privilege Success. All done!
Work with MySQL Server
Login to MySQL server as the MySQL root user.
mysql -u root -p
Output:
Enter password: << Enter MySQL Root Password
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 12
Server version: 8.0.13 Source distribution Copyright (c) 2000, 2018, 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>
Install phpMyAdmin
If you are a newbie to MySQL and have less know knowledge on MySQL command line, consider installing phpMyAdmin, an open-source web-based management tool to manage MySQL and MariaDB databases.
READ: How To Install phpMyAdmin with Apache on CentOS 8 / RHEL 8
READ: How To Install phpMyAdmin with Nginx on CentOS 8 / RHEL 8
Notes for MySQL 8.0 installed from MySQL Dev Community repository:
MySQL 8.0 uses a caching_sha2_password mechanism for authentication which prevents legacy application to access databases including phpMyAdmin at this moment. In simple terms, you won’t be login to phpMyAdmin unless we disable this new password mechanism.
You can globally disable the new password mechanism by placing default-authentication-plugin=mysql_native_password in /etc/my.cnf (Users created after this change will have mysql_native_password authentication mechanism) or you can revert to the old native authentication (mysql_native_password) for individual users (Ex: root) by running ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_password BY ‘<password>’; command in MySQL terminal.
Conclusion
In this article, you have learned how to install MySQL 8.0 on CentOS 8 / RHEL 8. Please share your feedback in the comments section.