• Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate
TecNStuff
Menu
  • Home
  • Linux
  • Ubuntu
  • Debian
  • CentOS
  • Linux Commands
  • About Us
  • Donate

How to Install MySQL on CentOS 7 Server

Written by Admin, Updated On May 7, 2019
centos, mariadb, mysql
How to Install MySQL on CentOS 7

MySQL is an open-source and widely used database management system. With CentOS 7 release MySQL is replaced with MariaDB as default database system. This guide will show you how to install MySQL on CentOS 7 systems.

Prerequisites#

Before starting, make sure you are logged in to a CentOS 7 server with a non-root user with sudo privileges.

Install MySQL on CentOS 7#

MySQL is not available in default CentOS 7 repositories so we will install the package from the MySQL Yum Repository. Below you will learn how to install MySQL 8.0 and MySQL 5.7 versions.

The latest version of MySQL is version 8.0. Below given repositories of both version 8.0 and 5.7 so choose repository to enable whichever version you wants to install. Follow below steps to install it on your CentOS 7 server.

First, enable the MySQL yum repository by typing:

For MySQL 8.0 Version
sudo yum localinstall https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm

For MySQL 5.7 Version
sudo yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

Now, install MySQL package same as any other package using yum by type:

sudo yum install mysql-community-server

During installation it may ask you to import MySQL GPG key. Type y and hit Enter to continue.

Manage MySQL Services#

Afterwards, when installation finish, Start MySQL service by below command:

sudo systemctl enable mysqld

Now enable MySQL service to automatically start on boot with:

sudo systemctl start mysqld

You can check status of MySQL service by:

sudo systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2019-03-29 01:39:01 UTC; 1 days ago
Docs: man:mysqld(8)
http://dev.mysql.com/doc/refman/en/using-systemd.html
Main PID: 423 (mysqld)
CGroup: /system.slice/mysqld.service
└─423 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

It will show you output as below and you can see that service is active or not:

Securing & Configuring MySQL#

MySQL includes a default security script which will improve security of MySQL installation. By this script it will make changes in default options like remote root logins and sample users and test database. Run the following security script:

sudo mysql_secure_installation

You will be prompted to enter your root user password of MySQL and also it will ask to set new root password. The password needs to be at least eight characters long and to contain at least one uppercase letter, one lowercase letter, one number, and one special character.

The existing password for the user account root has expired. Please set a new password.
New password:
Re-enter new password:

After that, it will prompt few more questions. For all next questions press Y and hit Enter key for each. By this it will remove anonymous users, test database, disable remote root logins and load these new rules so that MySQL immediately respects the changes you have made.

Testing MySQL#

We can connect MySQL via command line using MySQL client which is installed a dependency of the MySQL server package. You can login to MySQL using following command as root user :

sudo mysql -uroot -p

It will prompt to enter the root password which you have previously set. Once you will enter password it will be shown output as following :

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 276099
Server version: 8.0.11 MySQL Community Server (GPL)
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.

Conclusion#

In this guide, you learnt how to install and secure a MySQL server on a CentOS 7 server. If you have any suggestion or questions, you can post it using comment box below.

If our content helps you, please consider buying us a coffee

Thank you for your support.

Share On
Share on Facebook
Share on Twitter
Share on Reddit
Share on Tumblr
 Previous Article How to Set Up Apache Virtual Hosts on CentOS 7
Next Article   How To Install Apache on Ubuntu 18.04

Related Posts

  • How to Install MySQL on Debian 11

    How to Install MySQL on Debian 11

    November 28, 2022
  • How to Install MySQL on Ubuntu 22.04

    How to Install MySQL on Ubuntu 22.04

    November 27, 2022
  • How to Install MariaDB on Ubuntu 22.04

    How to Install MariaDB on Ubuntu 22.04

    November 24, 2022

Leave a Reply Cancel reply

DigitalOcean Referral Badge

Popular Posts

  • How to Install SSH Keys on Ubuntu 22.04
    How to Set up SSH Keys on Ubuntu 22.04 January 7, 2023
  • How to Install Mongodb on Debian 11
    How to Install MongoDB on Debian 11 Linux January 11, 2023
  • How to Install Puppet Agent on Ubuntu 22.04
    How to Install Puppet Agent on Ubuntu 22.04 January 22, 2023
  • How to Install Python 3.11 on Debian 11
    How to Install Python on Debian 11 January 25, 2023
  • How to Change-Hostname Ubuntu 22.04
    How to Change Hostname on Ubuntu 22.04 January 19, 2023
© 2020 TecNStuff All rights reserved. This website is using and storing cookies on your browser. By using this website you agree our Privacy Policy.  Follow us -  Twitter | Facebook