Install MySQL 5.7 and Python Connector on CentOS 7

MySQL is the most popular database management system used for powering web applications. MariaDB becomes the default database and MySQL is no longer available in CentOS 7. MariaDB is a drop in replacement for MySQL. In order to install MySQL, we have to install MySQL repository from mysql.com site.

Add MySQL repo:

[root@cms ~]# wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
--2016-12-05 11:38:47--  http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm [following]
--2016-12-05 11:38:48--  http://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 104.122.9.166
Connecting to repo.mysql.com (repo.mysql.com)|104.122.9.166|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’

100%[=================================================================================================================>] 9,224       --.-K/s   in 0.003s

2016-12-05 11:38:48 (2.76 MB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved [9224/9224]

[root@cms ~]# yum install mysql57-community-release-el7-9.noarch.rpm
Loaded plugins: fastestmirror
Examining mysql57-community-release-el7-9.noarch.rpm: mysql57-community-release-el7-9.noarch
Marking mysql57-community-release-el7-9.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql57-community-release.noarch 0:el7-9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================
Package                                    Arch                    Version                 Repository                                                Size
===========================================================================================================================================================
Installing:
mysql57-community-release                  noarch                  el7-9                   /mysql57-community-release-el7-9.noarch                  8.6 k

Transaction Summary
===========================================================================================================================================================
Install  1 Package

Total size: 8.6 k
Installed size: 8.6 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql57-community-release-el7-9.noarch                                                                                                  1/1
Verifying  : mysql57-community-release-el7-9.noarch                                                                                                  1/1

Installed:
mysql57-community-release.noarch 0:el7-9

Complete!
[root@cms ~]#

Install MySQL:

[root@cms ~]# yum install mysql-community-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.fibergrid.in
* epel: epel.mirror.net.in
* extras: mirror.fibergrid.in
* updates: mirror.fibergrid.in
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.16-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.16-1.el7 for package: mysql-community-server-5.7.16-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.16-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.16-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.16-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.16-1.el7 will be installed
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.44-2.el7.centos will be obsoleted
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-6.el7.x86_64
---> Package mysql-community-libs.x86_64 0:5.7.16-1.el7 will be obsoleting
--> Running transaction check
---> Package mysql-community-libs-compat.x86_64 0:5.7.16-1.el7 will be obsoleting
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================
Package                                         Arch                       Version                            Repository                             Size
===========================================================================================================================================================
Installing:
mysql-community-libs                            x86_64                     5.7.16-1.el7                       mysql57-community                     2.1 M
replacing  mariadb-libs.x86_64 1:5.5.44-2.el7.centos
mysql-community-libs-compat                     x86_64                     5.7.16-1.el7                       mysql57-community                     2.0 M
replacing  mariadb-libs.x86_64 1:5.5.44-2.el7.centos
mysql-community-server                          x86_64                     5.7.16-1.el7                       mysql57-community                     152 M
Installing for dependencies:
mysql-community-client                          x86_64                     5.7.16-1.el7                       mysql57-community                      24 M
mysql-community-common                          x86_64                     5.7.16-1.el7                       mysql57-community                     271 k

Transaction Summary
===========================================================================================================================================================
Install  3 Packages (+2 Dependent packages)

Total download size: 180 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.16-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.16-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.7.16-1.el7.x86_64.rpm                                                                               | 271 kB  00:00:00
(2/5): mysql-community-libs-5.7.16-1.el7.x86_64.rpm                                                                                 | 2.1 MB  00:00:00
(3/5): mysql-community-libs-compat-5.7.16-1.el7.x86_64.rpm                                                                          | 2.0 MB  00:00:00
(4/5): mysql-community-client-5.7.16-1.el7.x86_64.rpm                                                                               |  24 MB  00:00:14
(5/5): mysql-community-server-5.7.16-1.el7.x86_64.rpm                                                                               | 152 MB  00:01:15
-----------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                      2.3 MB/s | 180 MB  00:01:17
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package    : mysql57-community-release-el7-9.noarch (@/mysql57-community-release-el7-9.noarch)
From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-community-common-5.7.16-1.el7.x86_64                                                                                              1/6
Installing : mysql-community-libs-5.7.16-1.el7.x86_64                                                                                                2/6
Installing : mysql-community-client-5.7.16-1.el7.x86_64                                                                                              3/6
Installing : mysql-community-server-5.7.16-1.el7.x86_64                                                                                              4/6
Installing : mysql-community-libs-compat-5.7.16-1.el7.x86_64                                                                                         5/6
Erasing    : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                                                                                               6/6
Verifying  : mysql-community-libs-5.7.16-1.el7.x86_64                                                                                                1/6
Verifying  : mysql-community-libs-compat-5.7.16-1.el7.x86_64                                                                                         2/6
Verifying  : mysql-community-client-5.7.16-1.el7.x86_64                                                                                              3/6
Verifying  : mysql-community-common-5.7.16-1.el7.x86_64                                                                                              4/6
Verifying  : mysql-community-server-5.7.16-1.el7.x86_64                                                                                              5/6
Verifying  : 1:mariadb-libs-5.5.44-2.el7.centos.x86_64                                                                                               6/6

Installed:
mysql-community-libs.x86_64 0:5.7.16-1.el7      mysql-community-libs-compat.x86_64 0:5.7.16-1.el7      mysql-community-server.x86_64 0:5.7.16-1.el7

Dependency Installed:
mysql-community-client.x86_64 0:5.7.16-1.el7                                 mysql-community-common.x86_64 0:5.7.16-1.el7

Replaced:
mariadb-libs.x86_64 1:5.5.44-2.el7.centos

Complete!
[root@cms ~]#

The default temporary password for mysql now exists in /var/log/mysqld.log

Reset the password and start MySQL service.

[root@cms ~]# systemctl start mysqld
[root@cms ~]# systemctl status mysqld
● mysqld.service - MySQL Server
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
Active: active (running) since Mon 2016-12-05 12:13:20 EST; 8s ago
Process: 4833 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
Process: 4816 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
Main PID: 4837 (mysqld)
CGroup: /system.slice/mysqld.service
└─4837 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Dec 05 12:13:20 cms.microsemi.com systemd[1]: Starting MySQL Server...
Dec 05 12:13:20 cms.microsemi.com systemd[1]: Started MySQL Server.
[root@cms ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.16 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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> select version();
+-----------+
| version() |
+-----------+
| 5.7.16    |
+-----------+
1 row in set (0.00 sec)

mysql>

Download & Install Python connector:

[root@cms ~]# wget http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.4-1.el7.x86_64.rpm
--2016-12-05 12:20:01--  http://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-2.1.4-1.el7.x86_64.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-2.1.4-1.el7.x86_64.rpm [following]
--2016-12-05 12:20:01--  http://cdn.mysql.com//Downloads/Connector-Python/mysql-connector-python-2.1.4-1.el7.x86_64.rpm
Resolving cdn.mysql.com (cdn.mysql.com)... 104.122.9.166
Connecting to cdn.mysql.com (cdn.mysql.com)|104.122.9.166|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 243160 (237K) [application/x-redhat-package-manager]
Saving to: ‘mysql-connector-python-2.1.4-1.el7.x86_64.rpm’

100%[=================================================================================================================>] 243,160      414KB/s   in 0.6s

2016-12-05 12:20:02 (414 KB/s) - ‘mysql-connector-python-2.1.4-1.el7.x86_64.rpm’ saved [243160/243160]

[root@cms ~]# yum install mysql-connector-python-2.1.4-1.el7.x86_64.rpm
Loaded plugins: fastestmirror
Examining mysql-connector-python-2.1.4-1.el7.x86_64.rpm: mysql-connector-python-2.1.4-1.el7.x86_64
Marking mysql-connector-python-2.1.4-1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package mysql-connector-python.x86_64 0:2.1.4-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================
Package                               Arch                  Version                       Repository                                                 Size
===========================================================================================================================================================
Installing:
mysql-connector-python                x86_64                2.1.4-1.el7                   /mysql-connector-python-2.1.4-1.el7.x86_64                1.1 M

Transaction Summary
===========================================================================================================================================================
Install  1 Package

Total size: 1.1 M
Installed size: 1.1 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : mysql-connector-python-2.1.4-1.el7.x86_64                                                                                               1/1
Verifying  : mysql-connector-python-2.1.4-1.el7.x86_64                                                                                               1/1

Installed:
mysql-connector-python.x86_64 0:2.1.4-1.el7

Complete!
[root@cms ~]#

It’s very easy to install MySQL and Python connector.

2 Comments

  1. when i run mysql_secure_installation command i get an error
    Error: Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) .and if i start any mysqld service also
    Job for mysqld.service failed because the control process exited with error code. See “systemctl status mysqld.service” and “journalctl -xe” for details.

    • Krishna Prajapati

      Hello Kavya,

      You are getting this error because MySQL Server is not running and you are trying to run “mysql_secure_installation”.
      look at socket in my.cnf and try to fix the issue with proper permissions and privileges for /var/lib/mysql

Leave a Reply

Your email address will not be published. Required fields are marked *