Install and configure MySQL database on Linux platform

Keywords: MySQL RPM SHA1 MariaDB

Linux system version: CentOS 7.4
MySQL version: 5.7.28
There are three installation methods in Linux platform, RPM package, binary package and source package. This file mainly takes RPM package as an example to introduce how to install MySQL on Linux platform.
Download address: https://dev.mysql.com/downloads/mysql/

The specific steps to install RPM package are as follows:
(1) first uninstall mariadb, or it will conflict with the library required for mysql installation.

[root@localhost ~]# rpm -qa | grep mariadb
mariadb-libs-5.5.56-2.el7.x86_64
[root@localhost ~]# rpm -e --nodeps mariadb-libs-5.5.56-2.el7.x86_64

(2) switch to root (only root can execute RPM package):

[sunan@localhost ~]$ su - root
Password:
Last login: Mon Oct 28 20:12:16 CST 2019 from 192.168.1.19 on pts/0

(3) decompress the installation package:

[root@localhost opt]# tar -xvf mysql-5.7.28-1.el7.x86_64.rpm-bundle.tar
mysql-community-embedded-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-compat-5.7.28-1.el7.x86_64.rpm
mysql-community-libs-5.7.28-1.el7.x86_64.rpm
mysql-community-test-5.7.28-1.el7.x86_64.rpm
mysql-community-common-5.7.28-1.el7.x86_64.rpm
mysql-community-embedded-devel-5.7.28-1.el7.x86_64.rpm
mysql-community-client-5.7.28-1.el7.x86_64.rpm
mysql-community-server-5.7.28-1.el7.x86_64.rpm

(4) install the decompressed packages. These packages do not need to be installed completely, but pay attention to the installation sequence, which is interdependent:

[root@localhost opt]# rpm -ivh mysql-community-common-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-common-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-common-5.7.28-1.e################################# [100%]

[root@localhost opt]# rpm -ivh mysql-community-libs-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-libs-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-5.7.28-1.el7################################# [100%]

[root@localhost opt]# rpm -ivh mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-libs-compat-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-libs-compat-5.7.2################################# [100%]

[root@localhost opt]# rpm -ivh mysql-community-client-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-client-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-client-5.7.28-1.e################################# [100%]

[root@localhost opt]# rpm -ivh mysql-community-server-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-server-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-server-5.7.28-1.e################################# [100%]

[root@localhost opt]# rpm -ivh mysql-community-devel-5.7.28-1.el7.x86_64.rpm
warning: mysql-community-devel-5.7.28-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql-community-devel-5.7.28-1.el################################# [100%]

(5) after the installation, the database is initialized:

[root@localhost ~]# mysqld --initialize --user=mysql

(6) after initialization, generate a temporary database root password:

[root@localhost ~]# cat /var/log/mysqld.log
2019-10-28T13:59:16.673149Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2019-10-28T13:59:17.569975Z 0 [Warning] InnoDB: New log files created, LSN=45790
2019-10-28T13:59:17.639527Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2019-10-28T13:59:17.701489Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 21f571cf-f98b-11e9-add4-000c29eb2c51.
2019-10-28T13:59:17.705734Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2019-10-28T13:59:18.493027Z 0 [Warning] CA certificate ca.pem is self signed.
2019-10-28T13:59:18.708430Z 1 [Note] A temporary password is generated for root@localhost: )DrGVQo+s6-s

(7) start MySQL:

[root@localhost ~]# systemctl start mysqld.service
[root@localhost ~]# systemctl status mysqld.service
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: active (running) since Mon 2019-10-28 22:05:55 CST; 24s ago
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html
  Process: 1599 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS)
  Process: 1582 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS)
 Main PID: 1603 (mysqld)
   CGroup: /system.slice/mysqld.service
           └─1603 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Oct 28 22:05:55 localhost.localdomain systemd[1]: Starting MySQL Server...
Oct 28 22:05:55 localhost.localdomain systemd[1]: Started MySQL Server.

(8) log in to MySQL database and set a new password:

[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.28

Copyright (c) 2000, 2019, 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 password = password('Enter a new password');
Query OK, 0 rows affected, 1 warning (0.00 sec)

Posted by UnknownPlayer on Tue, 29 Oct 2019 09:27:04 -0700