YouTube Icon

Code Playground.

Install MySQL on CentOS 7


Install MySQL on CentOS 7

With the arrival of CentOS 7 MySQL, the world's most famous open-source social information base administration framework is not, at this point accessible in the CentOS's archives and MariaDB has become the default information base framework. MariaDB is a retrogressive viable, paired drop-in substitution of MySQL. 

In this instructional exercise, we will tell you the best way to introduce MySQL on a CentOS 7 machine. 

On the off chance that you need to introduce MariaDB rather than MySQL check our instructional exercise for establishment directions. 


Prior to beginning with this instructional exercise, ensure you are signed into your worker with a client account with sudo advantages or with the root client. It is best practice to run authoritative orders as sudo client rather than root, on the off chance that you don't have a sudo client on your framework you can make one by adhering to these directions . 

As we referenced in the presentation MySQL isn't accessible in the default CentOS 7 storehouses so we will introduce the bundles from the MySQL Yum Repository . In the accompanying segments, we will tell you the best way to introduce MySQL 8.0 and MySQL 5.7. 

You ought to introduce just a single MySQL adaptation on your CentOS 7 worker. In the event that you don't know which form to introduce counsel the documentation of the applications you will convey on your worker. 

Install MySQL 8.0 on CentOS 7

At the hour of composing this article, the most recent variant of MySQL is rendition 8.0. To introduce it on your CentOS 7 worker follow the means underneath: 

Empower the MySQL 8.0 store with the accompanying order: 

sudo yum localinstall

Introduce MySQL 8.0 bundle with yum: 

sudo yum install mysql-community-server

During the establishment yum may provoke you to import the MySQL GPG key. Type y and hit Enter. 

Install MySQL 5.7 on CentOS 7

To introduce the past stable arrival of MySQL, MySQL rendition 5.7 on a CentOS 7 worker, follow the means underneath: 

Empower the MySQL 5.7 storehouse with the accompanying order: 

sudo yum localinstall

Introduce MySQL 5.7 bundle with: 

Introduce MySQL as some other bundle utilizing yum: 

sudo yum install mysql-community-server

Areas underneath are pertinent for both MySQL 8.0 and MySQL 5.7. 

Beginning MySQL 

When the establishment is finished, start the MySQL administration and empower it to consequently begin on boot with: 

sudo systemctl enable mysqld
sudo systemctl start mysqld

We can check the MySQL administration status by composing: 

sudo systemctl status mysqld
? mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Wed 2018-05-23 11:02:43 UTC; 14min ago
     Docs: man:mysqld(8)
  Process: 4293 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 4310 (mysqld)
   CGroup: /system.slice/mysqld.service
           ??4310 /usr/sbin/mysqld

Securing MySQL

At the point when the MySQL worker is begun unexpectedly, an impermanent secret phrase is created for the MySQL root client. You can discover the secret word by running the accompanying order: 

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

The yield should look something like this: 

2018-05-23T10:59:51.251159Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: q&0)V!?fjksL

Make note of the secret word, on the grounds that the following order will request that you enter the transitory root secret word. 

Run the mysql_secure_installation order to improve the security of our MySQL establishment: 

sudo mysql_secure_installation
Securing the MySQL server deployment.

Enter password for user root:

Subsequent to entering the brief secret word you will be approached to set another secret key for client root. The secret word should be at any rate 8-characters in length and to contain at any rate one capitalized letter, one lowercase letter, one number, and one uncommon character. 

The existing password for the user account root has expired. Please set a new password.

New password:

Re-enter new password:

The content will likewise request that you eliminate the unknown client, confine root client admittance to the neighborhood machine and eliminate the test information base. You should answer "Y" (yes) to all inquiries. 

Connecting to MySQL from the command line

To communicate with MySQL through the terminal we will utilize the MySQL customer which is introduced as a reliance of the MySQL worker bundle. 

To sign in to the MySQL worker as the root client type: 

mysql -u root -p

You will be provoked to enter the root secret word you have recently set when the mysql_secure_installation content was run. 

When you enter the secret word you will be given the mysql shell as demonstrated as follows: 

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
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

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

Create a Database

Whenever you are associated with the MySQL shell, you can make another information base by composing the accompanying order: 

CREATE DATABASE new_database;
Query OK, 1 row affected (0.00 sec)

Create Tables

Since we made an information base we can make a table to store some information. 

Prior to running the SQL explanations for making a table we need to interface with the information base: 

use new_database;

In this model we will make a basic table named contacts with three fields, id, name and email: 

CREATE TABLE contacts (
  name VARCHAR(30),
  email VARCHAR(30)
Query OK, 1 row affected (0.00 sec)


In this instructional exercise, we've told you the best way to introduce and make sure about a MySQL worker on a CentOS 7 worker. We have additionally told you the best way to associate with the MySQL shell and how to make another information base and table.