In this tutorial we will learn how to install MySQL version 8.0 database on CentOS 8 operating system.
Introduction
MySQL is a popular relational database management sustem which was used by many popular websites, including Facebook,Flickr,MediaWiki,Twitter,YouTube, etc. MySQL is free and open-source software under the terms of the GNU General Public License, and is also available under a variety of proprietary licenses. MySQL is a component of the LAMP web application software stack, which is an acronym for Linux, Apache, MySQL, Perl/PHP/Python. MySQL is used by many database-driven web applications, including WordPress, phpBB, Drupal, Joomla. In this tutorial will learn how to install MySQL version 8.0 on an Rocky Linux 8 server.
Installing MySQL 8 On CentOS 8
On this tutorial we will use MySQL Yum repository to install MySQL on CentOS 8 operating system. MySQL Yum repository provides RPM packages for installing the MySQL server and other products. The MySQL 8 installation on CentOS 8 on this tutorial will consist of several stages, namely:
- Adding MySQL Yum Repository
- Selecting a Series Release
- Installing MySQL 8 on CentOS 8
- Securing MySQL 8 Database
- Testing MySQL server
Detailed explanation of each item will be explained in the following sub-chapters.
1. Adding the MySQL Yum Repository
On this stage, we will add MySQL Yum repository to our CentOS 8 system’s repository. The step is as follow :
# sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
Output :
[ramans@otodiginet ~]# sudo rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm Retrieving https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm warning: /var/tmp/rpm-tmp.SeyHUg: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY Verifying... ################################# [100%] Preparing... ################################# [100%] Updating / installing... 1:mysql80-community-release-el8-1 ################################# [100%]
2. Selecting a Release Series
Within the MySQL Yum repository, different release series of the MySQL Community Server are hosted in different subrepositories. The subrepository for the latest GA series (currently MySQL 8.0) is enabled by default, and the subrepositories for all other series (for example, the MySQL 8.0 series) are disabled by default. To do this step we will do following tasks :
# sudo dnf repolist all | grep mysql | grep enabled
Output :
[ramans@otodiginet ~]# sudo dnf repolist all | grep mysql | grep enabled mysql-connectors-community MySQL Connectors Community enabled mysql-tools-community MySQL Tools Community enabled mysql80-community MySQL 8.0 Community Server enabled
3. Installing MySQL 8 on CentOS 8
To Install MySQL we will submit the following command line :
#sudo dnf --disablerepo=AppStream install mysql-community-server -y
Output :
[ramans@otodiginet ~]#sudo dnf --disablerepo=AppStream install mysql-community-server -y ELRepo.org Community Enterprise Linux Repository - el8 830 B/s | 2.9 kB 00:03 ELRepo.org Community Enterprise Linux Repository - el8 23 kB/s | 285 kB 00:12 Extra Packages for Enterprise Linux Modular 8 - x86_64 11 kB/s | 34 kB 00:03 Extra Packages for Enterprise Linux 8 - x86_64 9.9 kB/s | 34 kB 00:03 Extra Packages for Enterprise Linux 8 - x86_64 38 kB/s | 7.4 MB 03:18 MySQL 8.0 Community Server 174 kB/s | 919 kB 00:05 MySQL Connectors Community 11 kB/s | 33 kB 00:02 MySQL Tools Community 40 kB/s | 109 kB 00:02 Oracle Linux / RHEL / CentOS-8 / x86_64 - VirtualBox 72 B/s | 181 B 00:02 Dependencies resolved. ==================================================================================================== Package Architecture Version Repository Size ==================================================================================================== Installing: mysql-community-server x86_64 8.0.21-1.el8 mysql80-community 53 M Installing dependencies: mysql-community-client x86_64 8.0.21-1.el8 mysql80-community 12 M mysql-community-common x86_64 8.0.21-1.el8 mysql80-community 621 k mysql-community-libs x86_64 8.0.21-1.el8 mysql80-community 1.4 M perl-Encode x86_64 4:2.97-3.el8 BaseOS 1.5 M perl-File-Temp noarch 0.230.600-1.el8 BaseOS 63 k perl-Getopt-Long noarch 1:2.50-4.el8 BaseOS 63 k perl-HTTP-Tiny noarch 0.074-1.el8 BaseOS 58 k perl-MIME-Base64 x86_64 3.15-396.el8 BaseOS 31 k perl-Pod-Escapes noarch 1:1.07-395.el8 BaseOS 20 k perl-Pod-Perldoc noarch 3.28-396.el8 BaseOS 86 k perl-Pod-Simple noarch 1:3.35-395.el8 BaseOS 213 k perl-Pod-Usage noarch 4:1.69-395.el8 BaseOS 34 k perl-Storable x86_64 1:3.11-3.el8 BaseOS 98 k perl-Term-ANSIColor noarch 4.06-396.el8 BaseOS 46 k perl-Term-Cap noarch 1.17-395.el8 BaseOS 23 k perl-Text-ParseWords noarch 3.30-395.el8 BaseOS 18 k perl-Time-Local noarch 1:1.280-1.el8 BaseOS 34 k perl-podlators noarch 4.11-1.el8 BaseOS 118 k Transaction Summary ==================================================================================================== Install 19 Packages Total download size: 69 M Installed size: 329 M Downloading Packages: (1/19): perl-File-Temp-0.230.600-1.el8.noarch.rpm 25 kB/s | 63 kB 00:02 (2/19): perl-Getopt-Long-2.50-4.el8.noarch.rpm 26 kB/s | 63 kB 00:02 (3/19): perl-MIME-Base64-3.15-396.el8.x86_64.rpm 36 kB/s | 31 kB 00:00 (4/19): perl-HTTP-Tiny-0.074-1.el8.noarch.rpm 47 kB/s | 58 kB 00:01 (5/19): perl-Pod-Escapes-1.07-395.el8.noarch.rpm 50 kB/s | 20 kB 00:00 (6/19): perl-Pod-Perldoc-3.28-396.el8.noarch.rpm 87 kB/s | 86 kB 00:00 (7/19): perl-Pod-Usage-1.69-395.el8.noarch.rpm 79 kB/s | 34 kB 00:00 (8/19): perl-Pod-Simple-3.35-395.el8.noarch.rpm 104 kB/s | 213 kB 00:02 (9/19): perl-Storable-3.11-3.el8.x86_64.rpm 125 kB/s | 98 kB 00:00 (10/19): perl-Term-ANSIColor-4.06-396.el8.noarch.rpm 138 kB/s | 46 kB 00:00 (11/19): perl-Term-Cap-1.17-395.el8.noarch.rpm 70 kB/s | 23 kB 00:00 (12/19): perl-Text-ParseWords-3.30-395.el8.noarch.rpm 63 kB/s | 18 kB 00:00 (13/19): perl-Time-Local-1.280-1.el8.noarch.rpm 104 kB/s | 34 kB 00:00 (14/19): perl-Encode-2.97-3.el8.x86_64.rpm 209 kB/s | 1.5 MB 00:07 (15/19): perl-podlators-4.11-1.el8.noarch.rpm 120 kB/s | 118 kB 00:00 (16/19): mysql-community-common-8.0.21-1.el8.x86_64.rpm 240 kB/s | 621 kB 00:02 (17/19): mysql-community-libs-8.0.21-1.el8.x86_64.rpm 393 kB/s | 1.4 MB 00:03 (18/19): mysql-community-client-8.0.21-1.el8.x86_64.rpm 598 kB/s | 12 MB 00:20 (19/19): mysql-community-server-8.0.21-1.el8.x86_64.rpm 762 kB/s | 53 MB 01:10 ---------------------------------------------------------------------------------------------------- Total 865 kB/s | 69 MB 01:21 warning: /var/cache/dnf/mysql80-community-b1f1ed5ba88ce0f8/packages/mysql-community-client-8.0.21-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 : mysql-community-common-8.0.21-1.el8.x86_64 1/19 Installing : perl-Text-ParseWords-3.30-395.el8.noarch 2/19 Installing : perl-MIME-Base64-3.15-396.el8.x86_64 3/19 Installing : mysql-community-libs-8.0.21-1.el8.x86_64 4/19 Running scriptlet: mysql-community-libs-8.0.21-1.el8.x86_64 4/19 Installing : mysql-community-client-8.0.21-1.el8.x86_64 5/19 Installing : perl-Time-Local-1:1.280-1.el8.noarch 6/19 Installing : perl-HTTP-Tiny-0.074-1.el8.noarch 7/19 Installing : perl-Term-Cap-1.17-395.el8.noarch 8/19 Installing : perl-Term-ANSIColor-4.06-396.el8.noarch 9/19 Installing : perl-Storable-1:3.11-3.el8.x86_64 10/19 Installing : perl-Pod-Escapes-1:1.07-395.el8.noarch 11/19 Installing : perl-File-Temp-0.230.600-1.el8.noarch 12/19 Installing : perl-Pod-Perldoc-3.28-396.el8.noarch 13/19 Installing : perl-Pod-Simple-1:3.35-395.el8.noarch 14/19 Installing : perl-Getopt-Long-1:2.50-4.el8.noarch 15/19 Installing : perl-Encode-4:2.97-3.el8.x86_64 16/19 Installing : perl-Pod-Usage-4:1.69-395.el8.noarch 17/19 Installing : perl-podlators-4.11-1.el8.noarch 18/19 Running scriptlet: mysql-community-server-8.0.21-1.el8.x86_64 19/19 Installing : mysql-community-server-8.0.21-1.el8.x86_64 19/19 Running scriptlet: mysql-community-server-8.0.21-1.el8.x86_64 19/19 Verifying : perl-Encode-4:2.97-3.el8.x86_64 1/19 Verifying : perl-File-Temp-0.230.600-1.el8.noarch 2/19 Verifying : perl-Getopt-Long-1:2.50-4.el8.noarch 3/19 Verifying : perl-HTTP-Tiny-0.074-1.el8.noarch 4/19 Verifying : perl-MIME-Base64-3.15-396.el8.x86_64 5/19 Verifying : perl-Pod-Escapes-1:1.07-395.el8.noarch 6/19 Verifying : perl-Pod-Perldoc-3.28-396.el8.noarch 7/19 Verifying : perl-Pod-Simple-1:3.35-395.el8.noarch 8/19 Verifying : perl-Pod-Usage-4:1.69-395.el8.noarch 9/19 Verifying : perl-Storable-1:3.11-3.el8.x86_64 10/19 Verifying : perl-Term-ANSIColor-4.06-396.el8.noarch 11/19 Verifying : perl-Term-Cap-1.17-395.el8.noarch 12/19 Verifying : perl-Text-ParseWords-3.30-395.el8.noarch 13/19 Verifying : perl-Time-Local-1:1.280-1.el8.noarch 14/19 Verifying : perl-podlators-4.11-1.el8.noarch 15/19 Verifying : mysql-community-client-8.0.21-1.el8.x86_64 16/19 Verifying : mysql-community-common-8.0.21-1.el8.x86_64 17/19 Verifying : mysql-community-libs-8.0.21-1.el8.x86_64 18/19 Verifying : mysql-community-server-8.0.21-1.el8.x86_64 19/19 Installed products updated. Installed: mysql-community-client-8.0.21-1.el8.x86_64 mysql-community-common-8.0.21-1.el8.x86_64 mysql-community-libs-8.0.21-1.el8.x86_64 mysql-community-server-8.0.21-1.el8.x86_64 perl-Encode-4:2.97-3.el8.x86_64 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-MIME-Base64-3.15-396.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-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-Time-Local-1:1.280-1.el8.noarch perl-podlators-4.11-1.el8.noarch Complete!
Verify MySQL version by submitting command line :
# mysql -Version
Output :
[ramans@otodiginet ~]# mysql -Version mysql Ver 8.0.21 for Linux on x86_64 (MySQL Community Server - GPL)
Currently, MySQL is installed on our CentOS 8 server but it isn’t yet operational. We need to start it with the systemctl
command line as shown below.
# systemctl start mysqld # systemctl enable mysqld # systemctl status mysqld
Output :
[ramans@otodiginet ~]# systemctl start mysqld [ramans@otodiginet ~]# systemctl enable mysqld [ramans@otodiginet ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2020-07-29 07:24:42 PDT; 29s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 5061 (mysqld) Status: "Server is operational" Tasks: 39 (limit: 23810) Memory: 435.2M CGroup: /system.slice/mysqld.service └─5061 /usr/sbin/mysqld Jul 29 07:24:23 otodiginet systemd[1]: Starting MySQL Server... Jul 29 07:24:42 otodiginet systemd[1]: Started MySQL Server.
At this step, we have MySQL 8 database server running on the server. To know MySQL root password, we retrieve it by submitting command line :
[ramans@otodiginet ~]# sudo cat /var/log/mysqld.log | grep -i 'temporary password' 2020-07-29T14:24:35.743714Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: wyY#%telw7ji
4. Securing MySQL 8 Database
MySQL installation script also includes a security script which allows us to change some default configuration options in order to improve MySQL’s security. To use the security script, we will run the command line :
# mysql_secure_installation
Output :
[ramans@otodiginet ~]# sudo mysql_secure_installation Securing the MySQL server deployment. 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: 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 ... 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 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 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 - 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 Success. All done!
5. Testing MySQL 8
On this stage, we have reached the final step. We will test installed MySQL 8 server by logging in and do several sql script inside it.
1. Log in to MySQL Server
We will connect to MySQL and retrieving some data to be displayed, we will do the following command line:
# mysql -u root -p
Output :
[root@otodiginet ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.21 MySQL Community Server - GPL Copyright (c) 2000, 2020, 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>
2. Create a new Database
mysql> create database otodiginet; Query OK, 1 row affected (0.01 sec) mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | otodiginet | | performance_schema | | sys | +--------------------+ 5 rows in set (0.07 sec)
Conclusion
In this tutorial we have learnt how to install MySQL 8 server on CentOS 8 opearting system. I hope this tutorial will be helpful.