The Heart Course of Installing MySQL on CentOS 7

Posted by Joopy on Fri, 12 Jul 2019 22:09:26 +0200

Today, there is a sudden whim to transfer the blog to your own cloud server. Well, it's a good idea, just able to practice. In order to do this, we must first have a database, linux with mysql. Ouch, that's good.

Two words don't mention the installation method of yum

[root@VM_235_40_centos ~]# yum install mysql
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.52-1.el7 for package: 1: mariadb-5.5.52-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.35-3.el7 will be updated
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package              Arch           Version                   Repository  Size
================================================================================
Installing:
 mariadb              x86_64         1:5.5.52-1.el7            os         8.7 M
Updating for dependencies:
 mariadb-libs         x86_64         1:5.5.52-1.el7            os         761 k

Transaction Summary
================================================================================
Install  1 Package
Upgrade             ( 1 Dependent package)

Total download size: 9.5 M
Is this ok [y/d/N]: y
Downloading packages:
Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
(1/2): mariadb-libs-5.5.52-1.el7.x86_64.rpm                | 761 kB   00:00
(2/2): mariadb-5.5.52-1.el7.x86_64.rpm                     | 8.7 MB   00:00
--------------------------------------------------------------------------------
Total                                               16 MB/s | 9.5 MB  00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : 1:mariadb-libs-5.5.52-1.el7.x86_64                           1/3
  Installing : 1:mariadb-5.5.52-1.el7.x86_64                                2/3
  Cleanup    : 1:mariadb-libs-5.5.35-3.el7.x86_64                           3/3
  Verifying  : 1:mariadb-5.5.52-1.el7.x86_64                                1/3
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                           2/3
  Verifying  : 1:mariadb-libs-5.5.35-3.el7.x86_64                           3/3

Installed:
  mariadb.x86_64 1:5.5.52-1.el7

Dependency Updated:
  mariadb-libs.x86_64 1:5.5.52-1.el7

Complete!

I don't know if it was too exciting at that time, and I filled in yes without looking at the installation prompt. When I finished installing, I was foolish. What's MariaDB? Unheard of, I rushed to ask Du Niang, originally a branch of mysql.

I want a "main room", but you set me a "third child"; want to raise a dolphin, you TM give me a seal.
Bedroom, I said this is one of the three IT giants, ah, yum library even has no mysql.

Decisively delete "Xiaosan"

[root@VM_235_40_centos ~]# yum erase mysql
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package          Arch            Version                    Repository    Size
================================================================================
Removing:
 mariadb          x86_64          1:5.5.52-1.el7             @os           48 M

Transaction Summary
================================================================================
Remove  1 Package

Installed size: 48 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing    : 1:mariadb-5.5.52-1.el7.x86_64                                1/1
  Verifying  : 1:mariadb-5.5.52-1.el7.x86_64                                1/1

Removed:
  mariadb.x86_64 1:5.5.52-1.el7

Complete!

Alas, do your own food and clothing, go shopping on the official website.



Foreign things are good, things for you, even the course is ready, unfortunately, I have not even CET-4 level of English ah, can not be hard to see.

Look at the specific steps given by the official website:

1. Add mysql yum Library

a. First, go to the download page of MySQL yum Library http://dev.mysql.com/downloads/repo/yum/

b. Find a distribution package that matches your platform and use the uname command to see your platform version

c. wget command to wrap the corresponding rpm, which is very small and only a few k

    [root@VM_235_40_centos ~]# wget https://repo.mysql.com//mysql57-community-release-el7-9.ch.rpm
    --2017-04-05 16:32:26--  https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
    Resolving repo.mysql.com (repo.mysql.com)... 23.50.25.213
    Connecting to repo.mysql.com (repo.mysql.com)|23.50.25.213|:443... 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 0s

    2017-04-05 16:32:28 (75.1 MB/s) - 'mysql57-community-release-el7-9.noarch.rpm' saved [9224/9224]

d. Install this package

    [root@VM_235_40_centos ~]# rpm -Uvh mysql57-community-release-el7-9.noarch.rpm
    warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5KEY
    Preparing...                          ################################# [100%]
    Updating / installing...
       1:mysql57-community-release-el7-9  ################################# [100%]

    [root@VM_235_40_centos ~]cd /etc/yum.repos.d
    #When the installation is complete, you will find that / etc/yum.repos.d has two more repo files for mysql
    [root@VM_235_40_centos yum.repos.d]# ls 
    CentOS-Base.repo  mysql-community-source.repo
    CentOS-Epel.repo  mysql-community.repo

2. Look at what's in the file.

    [root@VM_235_40_centos yum.repos.d]# more mysql-community.repo
    [mysql-connectors-community]
    name=MySQL Connectors Community
    baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    [mysql-tools-community]
    name=MySQL Tools Community
    baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    # Enable to use MySQL 5.5
    [mysql55-community]
    name=MySQL 5.5 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.5-community/el/7/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    # Enable to use MySQL 5.6
    [mysql56-community]
    name=MySQL 5.6 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-5.6-community/el/7/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    [mysql57-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

    [mysql80-community]
    name=MySQL 8.0 Community Server
    baseurl=http://repo.mysql.com/yum/mysql-8.0-community/el/7/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

    [mysql-tools-preview]
    name=MySQL Tools Preview
    baseurl=http://repo.mysql.com/yum/mysql-tools-preview/el/7/$basearch/
    enabled=0
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

According to the official website, you can configure the version of mysql you want to install in this file. If you need to install this version, you can set enabled=1, and if you don't need it, you can set it to 0. Here I install version 5.7

3. Once you're done, you can install mysql

[root@VM_235_40_centos yum.repos.d]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el6 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.17-1.el6 for package: mysql-communserver-5.7.17-1.el6.x86_64
......
---> Package mysql-community-libs.x86_64 0:5.7.17-1.el6 will be obsoleting
--> Finished Dependency Resolution
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
           Requires: libmysqlclient.so.18()(64bit)
           Removing: 1:mariadb-libs-5.5.52-1.el7.x86_64 (@os)
               libmysqlclient.so.18()(64bit)
           Obsoleted By: mysql-community-libs-5.7.17-1.el6.x86_64 (mysql57-community)
              ~libmysqlclient.so.20()(64bit)
Error: Package: 2:postfix-2.10.1-6.el7.x86_64 (@anaconda)
           Requires: libmysqlclient.so.18(libmysqlclient_18)(64bit)
           Removing: 1:mariadb-libs-5.5.52-1.el7.x86_64 (@os)
               libmysqlclient.so.18(libmysqlclient_18)(64bit)
           Obsoleted By: mysql-community-libs-5.7.17-1.el6.x86_64 (mysql57-community)
               Not found
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

Nanny, what the hell is wrong with the installation? It turned out that mariadb hadn't been deleted cleanly. My God, dig a hole and jump by yourself.

[root@VM_235_40_centos yum.repos.d]# rpm -qa|grep mariadb
mariadb-libs-5.5.52-1.el7.x86_64
[root@VM_235_40_centos yum.repos.d]# rpm -ev mariadb-libs-5.5.52-1.el7.x86_64 --nodeps
Preparing packages...
mariadb-libs-1:5.5.52-1.el7.x86_64

Once again

[root@VM_235_40_centos yum.repos.d]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el6 will be installed
......
---> Package mysql-community-libs.x86_64 0:5.7.17-1.el6 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================
 Package                       Arch          Version               Repository                Size
==================================================================================================
Installing:
 mysql-community-server        x86_64        5.7.17-1.el6          mysql57-community        151 M
Installing for dependencies:
 mysql-community-client        x86_64        5.7.17-1.el6          mysql57-community         23 M
 mysql-community-common        x86_64        5.7.17-1.el6          mysql57-community        328 k
 mysql-community-libs          x86_64        5.7.17-1.el6          mysql57-community        2.1 M
 numactl-libs                  x86_64        2.0.9-6.el7_2         os                        29 k

Transaction Summary
==================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 177 M
Installed size: 879 M
Is this ok [y/d/N]: y
Downloading packages:
mysql-community-common-5.7.17- FAILED
http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-common-5.7.17-1.el6.x86_64.rpm: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
mysql-community-client-5.7.17- FAILED
http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-client-5.7.17-1.el6.x86_64.rpm: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
......
Error downloading packages:
  mysql-community-server-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.
  mysql-community-common-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.
  mysql-community-libs-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.
  mysql-community-client-5.7.17-1.el6.x86_64: [Errno 256] No more mirrors to try.

Nima, there was another mistake. The software installed on Linux is a pain in the egg. The 404 error request failed. What the hell is this? I have poked around the installation process, or made a mistake, no way, silently asked Du Niang to go.
Here There is a blog, which says yum caching problem, okay, clear caching.

[root@VM_235_40_centos yum.repos.d]# cd /var/cache
[root@VM_235_40_centos cache]# ls
httpd  ldconfig  man  yum
[root@VM_235_40_centos cache]# cd yum
[root@VM_235_40_centos yum]# ls
x86_64
[root@VM_235_40_centos yum]# rm -drf x86_64
[root@VM_235_40_centos yum]# ls

Come back again

[root@VM_235_40_centos yum]# yum install mysql-community-server
Loaded plugins: fastestmirror, langpacks
epel                                                                       | 4.3 kB  00:00:00
extras                                                                     | 3.4 kB  00:00:00
mysql-connectors-community                                                 | 2.5 kB  00:00:00
mysql-tools-community                                                      | 2.5 kB  00:00:00
mysql57-community                                                          | 2.5 kB  00:00:00
os                                                                         | 3.6 kB  00:00:00
updates                                                                    | 3.4 kB  00:00:00
(1/10): epel/7/x86_64/group_gz                                             | 170 kB  00:00:00
(2/10): epel/7/x86_64/updateinfo                                           | 762 kB  00:00:00
(3/10): epel/7/x86_64/primary_db                                           | 4.6 MB  00:00:00
(4/10): extras/7/x86_64/primary_db                                         | 139 kB  00:00:00
(5/10): os/7/x86_64/group_gz                                               | 155 kB  00:00:00
(6/10): updates/7/x86_64/primary_db                                        | 3.8 MB  00:00:00
(7/10): os/7/x86_64/primary_db                                             | 5.6 MB  00:00:00
(8/10): mysql-connectors-community/x86_64/primary_db                       |  13 kB  00:00:00
(9/10): mysql-tools-community/x86_64/primary_db                            |  32 kB  00:00:00
(10/10): mysql57-community/x86_64/primary_db                               |  96 kB  00:00:01
Determining fastest mirrors
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el7 will be installed
......
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================
 Package                       Arch          Version               Repository                Size
==================================================================================================
Installing:
 mysql-community-server        x86_64        5.7.17-1.el7          mysql57-community        162 M
Installing for dependencies:
 mysql-community-client        x86_64        5.7.17-1.el7          mysql57-community         24 M
 mysql-community-common        x86_64        5.7.17-1.el7          mysql57-community        271 k
 mysql-community-libs          x86_64        5.7.17-1.el7          mysql57-community        2.1 M
 numactl-libs                  x86_64        2.0.9-6.el7_2         os                        29 k

Transaction Summary
==================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 188 M
Installed size: 847 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.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.17-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.7.17-1.el7.x86_64.rpm                      | 271 kB  00:00:03
(2/5): mysql-community-libs-5.7.17-1.el7.x86_64.rpm                        | 2.1 MB  00:00:52
(3/5): numactl-libs-2.0.9-6.el7_2.x86_64.rpm                               |  29 kB  00:00:00
(4/5): mysql-community-client-5.7. 6% [=-                       ] 101 kB/s |  12 MB  00:29:51 ETA

No problem, but my server bandwidth is not good, wait in silence.

Installed:
  mysql-community-server.x86_64 0:5.7.17-1.el7

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.17-1.el7
  mysql-community-common.x86_64 0:5.7.17-1.el7
  mysql-community-libs.x86_64 0:5.7.17-1.el7
  numactl-libs.x86_64 0:2.0.9-6.el7_2

Complete!

There should be applause here.

4. The last step is to start the service.


The installation guide of the official website uses service mysqld start, and CentOS7 uses the system CTL command to start the service. By default, the service command will switch to calling the system CTL command.

Additional steps to modify MySQL password

Previous versions of MySQL 5.7, if installed in this way, default to no password. For MySQL 5.7, which is a bit special, the following is the official website description of the installation process of MySQL 5.7:
- Service initialization
- Generate SSL certificates and keys in the data folder
- Install validate_password plug-in and take effect
- Create a database superadministrator'root@localhost'and generate a password for him

That is to say, MySQL 5.7 generated a password for the root superadministrator, which is in the / var/log/mysqld.log file.

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



The red circle part above is the instant password generated, and then enter mysql to modify the password. Of course, there are many ways to modify the password, which can be Baidu itself.

After two classes, TM finally ran out.

Summary of commands

Yum: Yellow dog Updater, Modified, a software installation tool to solve the dependence of RPM packages, can configure Yum in / etc/yum.config file. Yum data source is placed in / etc/yum.repos.d / folder by default. It can be considered as an enhanced version of rpm.
rpm: Red Hat Package Manager, the manager of software installation packages, can be used to install or delete software.
wget: World Wide Web Get, wget is a free tool for automatically downloading files from the network, supporting common protocols such as HTTP, HTTPS and FTP.
uname: Unix Name, which displays the name of the host operating system.

Topics: MySQL yum RPM MariaDB