How to Install MySQL 5.7 on CentOS 7

mahabub.devs3
Mahabubur Rahman
Published on Sep, 06 2024 4 min read 0 comments
image

MySQL is an open-source relational database management system.  It is the most popular open-source database in the world. It is commonly deployed as part of the LAMP stack (which stands for Linux, Apache, MySQL, and PHP) .

MySQL community has released MySQL 5.7 Release. Its available on MySQL official website. For this article We are using CentOS 7 AWS instance. For other Operating system version (Like: windows) you may download files from here. Also change the rpm names in all given commands in this tutorial.

This blog post will help you to install MySQL Server 5.7 on your CentOS 6 and Fedora systems.

Enable MySQL Repository

First of all, You need to enable MySQL 5.7 community release yum repository on your system. The rpm packages for yum repository configuration are available on MySQL’s official website.

First of all, import the latest MySQL GPG key to your system.


$ sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 

 

Now, use the below commands to configure the Yum repository as per your operating system version.
$ sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

 

Installing MySQL 5.7 Server

As you have successfully enabled MySQL yum repository on your system. Now, install MySQL 5.7 community server using the following commands as per your operating system version.
$ sudo yum install mysql-community-server 

 

The above command will install the MySQL community server and other dependencies on your system. During the installation process of packages, a temporary password is created and logged to MySQL log files. Use the following command to find your temporary MySQL password.

MySQL Service Run

After installing RPMs, use the following command to start MySQL Service.


$ sudo systemctl start mysqld 

 


$ sudo systemctl status mysqld 

 

Output● mysqld.service - MySQL 5.7 database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2020-03-12 14:07:41 UTC; 1min 7s ago
 Main PID: 15723 (mysqld)
   Status: "Server is operational"
    Tasks: 38 (limit: 5056)
   Memory: 474.2M
   CGroup: /system.slice/mysqld.service
           └─15723 /usr/libexec/mysqld --basedir=/usr

Mar 12 14:07:32 cent-mysql-3 systemd[1]: Starting MySQL 5.7 database server...
Mar 12 14:07:32 cent-mysql-3 mysql-prepare-db-dir[15639]: Initializing MySQL database
Mar 12 14:07:41 cent-mysql-3 systemd[1]: Started MySQL 5.7 database server.

Securing MySQL Configuration

Execute mysql_secure_installation script and follow the wizard. It will prompt for the root password. Use the temporary root password got in the above step.


$ /usr/bin/mysql_secure_installation

 

This wizard will prompt you for inputs. Input a new strong password for the MySQL root account. For remaining options read the option and provide input as required. We recommend pressing ‘y’ to all for better security.

Securing the MySQL server deployment.

Enter password for user root: **********

The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configuration
of the plugin.
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) : y

New password: ******************

Re-enter new 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
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!

Login to MySQL

Congratulations! You have successfully installed MySQL 5.7. Let login to MySQL using root access and try to create a dummy database. Use the password you have set already.


$ mysql -u root -p 

 

OutputEnter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.38 MySQL Community Server (GPL)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

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>

Check MySQL Version

Verify your MySQL version installed on your system. The following command will display installed MySQL version.


$  mysql -V

 

Outputmysql  Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using  EditLine wrapper

 

Conclusion

In this article, you have learned to install MySQL 5.7 on CentOS 7 systems.


 

0 Comments