Friday, June 30, 2017

A Quick Guide for MySQL Installation on Linux using the MySQL Yum Repository

Hello Guys, today I am writing this piece because, one of my close friend is struggling hard to install MySQL on his CentOS system. Although he was well aware of how to install, update or remove any software package using YUM but still he was out of luck. Someone might also face the same problem. This article would help all those who wants to install MySQL on different Linux distribution whether it is EL5-, EL6-, EL7- based platforms (Oracle Linux, Red Hat Enterprise Linux, CentOS) or Fedora 24 & 25. Depending upon requirement, one might want to install MySQL using a third-party-distributed RPM package but that is out of scope from this article.

Note: While writing this piece, I will be installing the MySQL 5.7 on Red Hat Enterprise Linux (CentOS 6.7).
In this article we would discuss below points:
Why MySQL Yum Repository?
How to add the MySQL Yum Repository to our system's repository list?
Which version of MySQL to install?
How to install MySQL using YUM?
How to start the MySQL Server?
Recap! What we did?


Why MySQL Yum Repository?

  • Official repository from MySQL, that provides RPM packages for installing the MySQL server, client, and other components on Linux platforms. 
  •  Installing Packages from here means, also upgrading and replacing any third-party MySQL packages installed from the Linux distros' native software repositories, if replacements for them are available from MySQL.

How to add the MySQL Yum Repository to our system's repository list?

Follow the below steps to add MySQL Yum Repository to our system's repository list:
  1. Select & download the release package for our platform from MySQL Yum repository at http://dev.mysql.com/downloads/repo/yum/.
    One can manually download it or use the wget command to download it like below:
    ~]$ wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm 
  2. Install the downloaded release package
    ~]$ sudo rpm -Uvh mysql57-community-release-el6-11.noarch.rpm
    warning: mysql57-community-release-el6-11.noarch.rpm: Header V3 DSA/SHA1 Signature,
     key ID 5072e1f5: NOKEY
    Preparing...                ########################################### [100%]
       1:mysql57-community-relea########################################### [100%]
    
    Note: Once the release package is installed in our system, any system-wide update by the yum update command will automatically upgrade MySQL packages on our system and also replace any native third-party packages, if Yum finds replacements for them in the MySQL Yum repository.

Which version of MySQL to install?

MySQL Yum repository (http://repo.mysql.com/yum/) contains different release series of the MySQL Community Server in different sub-repositories. Depending upon requirement, one can enable or disable the sub-repository for the specific series by using yum-config-manager command or by editing the /etc/yum.repos.d/mysql-community.repo file. But this must be done before running the installation command.

# See which sub-repositories enabled or disabled in the MySQL Yum repository
~]$ yum repolist all | grep mysql 
mysql-cluster-7.5-community        MySQL Cluster 7.5 Community   disabled
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - disabled
mysql-cluster-7.6-community        MySQL Cluster 7.6 Community   disabled
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - disabled
mysql-connectors-community         MySQL Connectors Community    enabled:     36
mysql-connectors-community-source  MySQL Connectors Community -  disabled
mysql-tools-community              MySQL Tools Community         enabled:     47
mysql-tools-community-source       MySQL Tools Community - Sourc disabled

# Enabling & disabling using yum-config-manager command
# disable the 5.7 series subrepository and enable the one for the 5.6 series
~]$ sudo yum-config-manager --disable mysql57-community
~]$ sudo yum-config-manager --enable mysql56-community

# Enabling & disabling using /etc/yum.repos.d/mysql-community.repo file
# Find the entry for sub-repository we want to configure, & edit the enabled option. 
# Specify enabled=0 to disable & enabled=1 to enable a sub-repository. 
# For Example: By default MySQL 5.7 is enabled
[mysql56-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

# Verify that the correct sub-repositories have been enabled and disabled 
~]$ yum repolist enabled | grep mysql
mysql-connectors-community MySQL Connectors Community                         36
mysql-tools-community      MySQL Tools Community                              47
mysql57-community          MySQL 5.7 Community Server                        183
Note: The sub-repository for the latest GA series (currently MySQL 5.7) is enabled by default, and the sub-repositories for all other series (for example, the MySQL 5.6 series) are disabled by default.

How to install MySQL using YUM?

~]$ sudo yum install mysql-community-server
Installed:
  mysql-community-libs.x86_64 0:5.7.18-1.el6 
  mysql-community-libs-compat.x86_64 0:5.7.18-1.el6 
  mysql-community-server.x86_64 0:5.7.18-1.el6

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.18-1.el6  mysql-community-common.x86_64 0:5.7.18-
  1.el6  
  numactl.x86_64 0:2.0.9-2.el6                  perl.x86_64 4:5.10.1-144.el6
  perl-Module-Pluggable.x86_64 1:3.90-144.el6   perl-Pod-Escapes.x86_64 1:1.04-144.el6        
  perl-Pod-Simple.x86_64 1:3.13-144.el6         perl-libs.x86_64 4:5.10.1-144.el6
  perl-version.x86_64 3:0.77-144.el6

Dependency Updated:
  postfix.x86_64 2:2.6.6-8.el6

Replaced:
  mysql-libs.x86_64 0:5.1.73-5.el6_6

Complete!

How to start the MySQL Server?

Use the below commands to start the MySQL server and check if it's started or not.
# Start the MySQL server
~]$ sudo service mysqld start
Initializing MySQL database:                               [  OK  ]
Installing validate password plugin:                       [  OK  ]
Starting mysqld:                                           [  OK  ]

# For EL7-based platforms, to start the MySQL server
~]$ sudo systemctl start mysqld.service

# Check the status of the MySQL server
~]$ sudo service mysqld status
mysqld (pid  6934) is running...

# For EL7-based platforms, to check the status of MySQL server
~]$ sudo systemctl status mysqld.service
As you can see, at the initial start up of the MySQL Server (for MySQL 5.7 only), we have got some important message. Let's discuss it here:
  •  The server is initialized.
  • The validate_password plugin is installed and enabled.
  • A superuser account 'root'@'localhost' is created. A password for the superuser is set and stored in the error log file.
It's recommended to change the root password by logging in with the generated, temporary password and set a custom password. Use below commands to do the same:
# See the temporary password 
~]$ sudo grep 'temporary password' /var/log/mysqld.log
2017-06-30T07:14:27.972685Z 1 [Note] A temporary password is generated for 
root@localhost: byZLza/(w0/c

# Login 
~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.18

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>

# Set a custom password 
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewP@ss51';
Query OK, 0 rows affected (0.00 sec)
Note: As MySQL's validate_password plugin is installed by default. This will require that passwords contain at least one upper case letter, one lower case letter, one digit, and one special character, and that the total password length is at least 8 characters.

Recap! What we did?

# Download the release package for our platform from MySQL Yum repository 
~]$ wget https://dev.mysql.com/get/mysql57-community-release-el6-11.noarch.rpm
~]$ sudo rpm -Uvh mysql57-community-release-el6-11.noarch.rpm //install release package
~]$ yum repolist enabled | grep mysql        //verify enabled repositories
~]$ sudo yum install mysql-community-server //install MySQL
~]$ sudo service mysqld start               //start the MySQL server
~]$ sudo service mysqld status             //check the status of the MySQL server
~]$ sudo grep 'temporary password' /var/log/mysqld.log // see the temporary password 
~]$ mysql -uroot -p //login to mysql console
mysql>ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewP@ss5'; //set a custom password 
That's it! We all done. Thank you for reading this article. Hope you would like it. If you have any suggestion or have any question do let me know in the comment box. Happy Learning!!

No comments:

Post a Comment