Click here for "Safe Air Conditioner Repair and Proper Freon Recovery".

CentOS 7.6 ; Installing MySQL

1.Download MySQL

So far, I’ve compiled the source and installed it, but I’m going to install mysql5.7 using mysql mysql mysql.
If you install CentOS7.6, mariaDB (a MySQL compatible DB) may be installed. If this remains, it will conflict with the MySQL you are about to install, so remove it first.

1.1 Delete mariaDB

Delete mariaDB
# rpm -qa | grep maria    Check if mariaDB exists.
# yum remove mariadb-libs
# rm -rf /var/lib/mysql/

1.2 Adding and configuring the official MySQL repository

①To install MySQL 5.6 or later, first install the repository from the official MySQL website.

Download the package for RHEL7 series and install it directly.
# yum install

②Verify that the repository has been added.

# yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community      invalid
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - So invalid
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community      invalid
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - So invalid
mysql-connectors-community/x86_64  MySQL Connectors Community       validity
mysql-connectors-community-source  MySQL Connectors Community - Sou invalid
mysql-tools-community/x86_64       MySQL Tools Community            validity
mysql-tools-community-source       MySQL Tools Community - Source   invalid
mysql-tools-preview/x86_64         MySQL Tools Preview              invalid
mysql-tools-preview-source         MySQL Tools Preview - Source     invalid
mysql55-community/x86_64           MySQL 5.5 Community Server       invalid
mysql55-community-source           MySQL 5.5 Community Server - Sou invalid
mysql56-community/x86_64           MySQL 5.6 Community Server       invalid
mysql56-community-source           MySQL 5.6 Community Server - Sou invalid
mysql57-community/x86_64           MySQL 5.7 Community Server       invalid
mysql57-community-source           MySQL 5.7 Community Server - Sou invalid
mysql80-community/x86_64           MySQL 8.0 Community Server     validity
mysql80-community-source           MySQL 8.0 Community Server - Sou invalid

③As it is, MySQL 8.0 will be installed, so we will change the configuration so that 5.7 will be installed.
To change the settings, the yum-utils package for changing yum settings is required, so install it if it is not already installed.

# yum list installed | grep yum-utils  ← Make sure yum-utils is installed.
# yum -y install yum-utils  ← If not, install yum-utils.

Disable MySQL 8.0 and enable MySQL 5.7

# yum-config-manager –disable mysql80-community  ← Disable MySQL 8.0
# yum-config-manager –enable mysql57-community ← Activate MySQL 5.7

2.Installing MySQL

2.1 Check the version of the package.

If the version is 5.7.xx, it’s OK to install.

# yum info mysql-community-server
名前 : mysql-community-server
architecture : x86_64
version : 5.7.24
release : 2.el6
Capacity: *** M
repository : installed
Provided by Repositories : mysql57-community
summary : A very fast and reliable SQL database server
License: Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.
Description :

2.2 Install

# yum -y install mysql-community-server
Check the version once it is installed.
# mysqld –version
mysqld Ver 5.7.24 for Linux on x86_64 (MySQL Community Server (GPL))

3.Mysql start/stop/autostart settings

# systemctl start mysqld  ← activation 
# systemctl stop mysqld  ← stop
# systemctl status mysqld  ← Status check
# systemctl restart mysqld  ← restart
# systemctl enable mysqld  ← Auto start ON
# systemctl start mysqld
Make sure it is set to auto-start.
# systemctl is-enabled mysqld
mysqld.service is not a native service, redirecting to /sbin/chkconfig. Executing /sbin/chkconfig mysqld –level=5
If it is enabled, auto-start is set to ON.Check with chkconfig
# chkconfig –list mysqld  ← Check the auto-start settings
0:off 1:off 2:on 3:on 4:on 5:on 6:off
If 2 to 5 are set to on, auto start is set to on.

4.Initialization of Mysql

4.1 Know the initial password for the root user

MySQL 5.7 sets a random string of characters as a password for the root user upon first startup. The initial password is printed out in the MySQL log file. The log file is /var/log/mysqld.log. If you open the log, you will find the password as follows

# vi  /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: ??XX;BB6Y
??XX;BB6Y Random initial password

4.2 Set the password for the root user.

①Change the root password to something different in mysql_secure_installation

$ mysql_secure_installation


In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

# Enter the current mysql root password, empty the first time.
Enter current password for root (enter for none):??XX;BB6Y
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

# Do you want to set a root password?
Set root password? [Y/n] y
New password: Any password
Re-enter new password: Same password again
Password updated successfully!
Reloading privilege tables..
… Success!

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.

# Do you want to delete an anonymous user?
Remove anonymous users? [Y/n] 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.

# Do you want to deny remote root login?
Disallow root login remotely? [Y/n] 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.

# Do you want to delete the test database?
Remove test database and access to it? [Y/n] y
– Dropping test database…
ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist
… Failed! Not critical, keep moving…
– Removing privileges on test database…
… Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

# Do you want to FLUSH PRIVILEGES now?
Reload privilege tables now? [Y/n] y
… Success!

All done! If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Cleaning up…

②From now on, you can login to MySQL with

# mysql -u root -p
password ;