Linux, Windows, Virtualization, OpenSource & Blogging

How To Install MySQL 5.7/8.0 on CentOS 7/6, RHEL 7/6 & Fedora 27/26/25

0

 

Install MySQL 8.0 on CentOS 7
Install MySQL 8.0 on CentOS 7

MySQL is a free and open source database management System, commonly used in web applications to store and retrieve records and information.

MySQL was initially developed by MYSQL AB, now owned by Oracle Corporation. It was the primary database application for Linux operating system until MariaDB, a fork of MySQL, came into the picture.

In this article, we will work on the task of how to Install MySQL 5.7 on CentOS 7/6, RHEL 7/6 & Fedora 27/26/25.

Add MySQL Repository

MySQL is no longer distributed through base operating system image or available in OS repositories. So, you would need to add an official repository of MySQL to install MySQL community server.

### CentOS 7 / RHEL 7 ###

rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

### CentOS 6 / RHEL 6 ###

rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm

### CentOS 5 / RHEL 5 ###

rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el5-8.noarch.rpm

### Fedora 27 ###

rpm -ivh https://dev.mysql.com/get/mysql57-community-release-fc27-10.noarch.rpm

### Fedora 26 ###

rpm -ivh https://dev.mysql.com/get/mysql57-community-release-fc26-10.noarch.rpm

### Fedora 25 ###

rpm -ivh https://dev.mysql.com/get/mysql57-community-release-fc25-10.noarch.rpm

Make sure the MySQL repository has been added and enabled by using the following command.

yum repolist all | grep mysql | grep enabled

Output: May Look like.

mysql-connectors-community/x86_64  MySQL Connectors Community     enabled:    42
mysql-tools-community/x86_64       MySQL Tools Community          enabled:    53
mysql57-community/x86_64           MySQL 5.7 Community Server     enabled:   227

Install MySQL Community Server

Oracle currently offers both stable version and beta version of MySQL. You can choose the one you want to install it on your machine.

Install MySQL 5.7

Use yum command in CentOS/RHEL and dnf command in Fedora to install the latest stable version of MySQL.

### CentOS 7/6 & RHEL 7/6 ###

yum -y install mysql-community-server

### Fedora 27/25/24 ###

dnf -y install mysql-community-server

Install MySQL 8.0 RC

If you want to try the beta version of MySQL, then install MySQL 8.0 RC on your machine.

### CentOS 7/6 & RHEL 7/6 ###

yum -y install mysql-community-server --enablerepo=mysql80-community

### Fedora 27/25/24 ###

dnf -y install mysql-community-server --enablerepo=mysql80-community

Start MySQL server

After the installation of MySQL, you can start MySQL server using the following command.

### CentOS 7 / RHEL 7 / Fedora 27/25/24 ###

systemctl start mysqld

### CentOS 6 / RHEL 6 ###

service mysqld start

Enable MySQL server at system startup.

### CentOS 7 / RHEL 7 / Fedora 27/25/24 ###

systemctl enable mysqld

### CentOS 6 / RHEL 6 ###

chkconfig mysqld on

Verify that MySQL server is started using the following command.

### CentOS 7 / RHEL 7 / Fedora 27/25/24 ###

systemctl status mysqld

### CentOS 6 / RHEL 6 ###

service mysqld status

Output:

CentOS 7 / RHEL 7 / Fedora:

 mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Sat 2017-11-25 02:02:14 EST; 1min 17s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
 Main PID: 1575 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─1575 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Nov 25 02:02:07 server.itzgeek.local systemd[1]: Starting MySQL Server...
Nov 25 02:02:14 server.itzgeek.local systemd[1]: Started MySQL Server.

CentOS 6 / RHEL 6 :

mysqld (pid 2258) is running...

Secure MySQL server

In CentOS/RHEL/Fedora, initial MySQL root password can be found in /var/log/mysqld.log. You can use below command to take the password from the log file.

cat /var/log/mysqld.log | grep -i 'temporary password'

Output:

2017-11-25T07:02:29.549979Z 1 [Note] A temporary password is generated for root@localhost: Ed*Sn(6R9q0h

Now, you need to run mysql_secure_installation to secure your MySQL installation. This command takes care of setting the root password, removing anonymous users, disallow root login remotely, etc.

mysql_secure_installation

Output:

Securing the MySQL server deployment.

Enter password for user root:  <== Enter Root password taken from previous step

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

New password: <== Enter New Root Password

Re-enter new password: <== Re-Enter New Root Password 
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) : no <== Since the password is already changed in previous step, type no.

 ... skipping.
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) : yes <== Remove Anonymous user
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) : yes <== Disable remote root login
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) : yes <== Remove test database
 - 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) : yes <== Reload Privilege
Success.

All done!

Work with MySQL Server

Login to MySQL server with the root user and its password.

mysql -u root -p

Output:

MySQL 5.7:

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

Copyright (c) 2000, 2017, 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.

mysql>

MySQL 8.0:

Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 8.0.3-rc-log MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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.

mysql>

Install phpMyAdmin

phpMyAdmin is an open source web-based management tool to manage MySQL and MariaDB databases. Follow below link to install and configure phpMyAdmin based on your operating system.

READ: Install phpMyAdmin on CentOS 7 / RHEL 7

READ: Install phpMyAdmin on Fedora 27 / Fedora 26/25/24

That’s All.

You might also like

How To Install MySQL 5.7/8.0 on CentOS 7/6, RHEL 7/6 & Fedora 27/26/25

0