How to install MySQL on CentOS 7

Share on Social Media

Learn how to install MySQL on CentOS 7 with this comprehensive guide. Follow our step-by-step instructions to set up and configure MySQL efficiently on your CentOS 7 system. #centlinux #linux #mysql

What is MySQL?

MySQL Server Community Edition (CE) is the free version of world’s most popular open source database server. It is distributed under GPL License and supported by a large and active community of open source developers. There is also a commercial version of MySQL server, which is developed and maintained by Oracle Corporation.

Read Also: How to install MariaDB on Rocky Linux 9

MySQL Server 8 Community Edition Features

Main features of MySQL Server CE are.

  • Supports SQL and NoSQL
  • Pluggable Storage Engine Architecture
  • MySQL Replication
  • MySQL InnoDB Cluster
  • MySQL Router
  • MySQL Partitioning
  • MySQL Workbench

Checkout complete list of MySQL Server 8 features at MySQL official website.

How to install MySQL on CentOS 7
How to install MySQL on CentOS 7

Linux Server Specification

We have configured a CentOS 7 virtual machine with following specifications.

  • CPU – 3.4 Ghz (2 cores)
  • Memory – 2 GB
  • Storage – 20 GB
  • Operating System – CentOS 7.6
  • Hostname – mysql-server.example.com
  • IP Address – 192.168.116.180/24

For an optimal environment when installing MySQL on CentOS 7, it is essential to have reliable hardware and accessories that support smooth server management and development workflows. A top choice is the Anker Nano 3-in-1 Portable iPhone Charger, a best-selling compact power bank ideal for keeping your devices charged during intensive server setups. Paired with this, the Logitech MX Master 3 Advanced Wireless Mouse enhances precision and comfort for managing lengthy terminal commands and configurations efficiently. These products are favorites among IT professionals for their durability and productivity aid.

Disclaimer: Please note, these are affiliate links, and purchases may benefit this blog at no extra cost to you.

Install MySQL Yum Repository

Connect with mysql-server.example.com using ssh as root user.

Download and install MySQL yum repository from MySQL official website.

rpm -ivh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

Output:

Retrieving https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
warning: /var/tmp/rpm-tmp.fJdAIJ: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql80-community-release-el7-3 ################################# [100%]

Build cache for MySQL yum repository.

yum makecache fast

Install MySQL on CentOS 7

We have added the MySQL yum repository, now we can install MySQL on CentOS 7 and relevant packages using yum command.

yum install -y mysql-community-server

MySQL service is automatically enabled by the installer. Therefore, we are only required to start mysqld.service once.

systemctl start mysqld.service

During first start-up, MySQL service generates a temporary password in /var/log/mysqld.log file.

Retrieve this password using following command.

grep 'temporary password' /var/log/mysqld.log

Output:

2019-06-24T14:23:17.605740Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: B4gqaLFg6p_Y

Note down this password, we will use it later.

Read Also: MySQL vs MariaDB vs Percona: A Complete Comparison (2025 Edition)

Securing MySQL Database Server

To configure and secure our MySQL database instance, we can use mysql_secure_installation command. We are also required to use temporary password to set a new password for root user.

mysql_secure_installation

Output:

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
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!

Connect with MySQL database server using mysql command as root user.

mysql -u root -p

Display list of mysql databases.

show databases;

Output:

+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.01 sec)

We have successfully install MySQL on CentOS 7.

Final Thoughts

Installing MySQL on CentOS 7 can be straightforward when you follow the right steps. This guide provides detailed instructions to help you set up and configure MySQL efficiently. If you encounter any challenges or need professional assistance, I offer expert services to help with your MySQL installation and configuration.

Your Linux servers deserve expert care! I provide reliable management and optimization services tailored to your needs. Discover how I can help!

Thank you for following this guide, and I look forward to assisting you with your MySQL projects!

If you’re serious about mastering databases and boosting your tech career, The Ultimate MySQL Bootcamp: Go from SQL Beginner to Expert by Colt Steele is one of the most practical and highly-rated online courses available. Designed for both beginners and professionals, this course walks you step-by-step from the fundamentals of SQL to advanced database management skills using real-world examples.

Whether you’re a developer, data analyst, or aspiring system administrator, this bootcamp will give you the confidence to work with MySQL like a pro. [Enroll today] and start building skills that employers value.

Disclaimer: This post contains affiliate links. If you purchase through these links, I may earn a small commission at no additional cost to you.

Leave a Reply