How To Install MySQL 8.0 on CentOS 7

How To Install MySQL 8.0 on CentOS 7

MySQL is a free, open-source database management system from Oracle. It is commonly used in web applications to store and retrieve records and information.

MySQL was originally developed by MYSQL AB and is now owned by Oracle Corporation. It was the primary database application for the Linux operating system until the release of MariaDB, a fork of MySQL.

In this post, we will see the steps to install MySQL 8.0 on CentOS 7.

Add MySQL Repository

MySQL is neither distributed through the base operating system image nor available in OS repositories. So, you would need to its official repository to install the MySQL community server.

yum install https://dev.mysql.com/get/mysql80-community-release-el7-2.noarch.rpm

Run the below command to ensure sure the MySQL repository has been added and enabled.

yum repolist all | grep mysql | grep enabled

Output:

mysql-connectors-community/x86_64      MySQL Connectors Communit enabled:     95
mysql-tools-community/x86_64           MySQL Tools Community     enabled:     84
mysql80-community/x86_64               MySQL 8.0 Community Serve enabled:     82

Install MySQL 8.0 Community Server

Oracle offers version 8.0 and v5.7. But, here, we go for MySQL v8.0. Use yum command in CentOS to install the latest stable version of MySQL.

yum -y install mysql-community-server

Start MySQL server

After the installation of the MySQL package, you can start MySQL server using the following command.

systemctl start mysqld

Enable MySQL server at system startup.

systemctl enable mysqld

Verify that the MySQL server is running 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 Tue 2019-03-19 00:19:12 EDT; 7s ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Main PID: 11548 (mysqld) Status: "SERVER_OPERATING" CGroup: /system.slice/mysqld.service └─11548 /usr/sbin/mysqld

Mar 19 00:18:58 server.linuxbees.local systemd[1]: Starting MySQL Server… Mar 19 00:19:12 server.linuxbees.local systemd[1]: Started MySQL Server.

Secure MySQL server

In CentOS, 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. This password is required for making the MySQL server secure.

cat /var/log/mysqld.log | grep -i 'temporary password'

Output:

2019-03-19T04:19:04.444173Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: X.khdzie1q95

Now, run mysql_secure_installation to secure your MySQL installation.

This command performs initial tasks such as 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 Root password taken from 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 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) : No <== Since the password is already changed in previous step, type No.

… 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) : Yes <== 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) : Yes <== Disable 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) : Yes <== 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) : Yes <== Reload Privilege Success.

All done!

Work with MySQL Server

Login to MySQL server with the root and the password you set while securing the MySQL.

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 15
Server version: 8.0.15 MySQL Community Server - GPL

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>

Conclusion

You have successfully installed MySQL 8.0 on CentOS 7. If you are a newbie and not comfortable in MySQL command line mode, you can use phpMyAdmin, an open source web-based management tool to manage MySQL and MariaDB databases.

comments powered by Disqus