MySQL 5.7------------------------------- Installation based on entOS6 binary package

Posted by Barnacles on Wed, 19 Jun 2019 18:54:57 +0200

1. Background

   * MySQL is a relational database management system developed by Swedish MySQL AB and currently owned by Oracle.MySQL is one of the most popular relational database management systems. In the application of WEB, MySQL is the best RDBMS (Relational Database Management System) application software.

   * MySQL is a relational database management system that increases speed and flexibility by keeping data in different tables instead of all data in one large warehouse.

   * The SQL language used by MySQL is the most commonly used standardized language for accessing databases.MySQL software uses a dual licensing policy, which is divided into community and commercial versions. Because of its small size, fast speed and low overall cost of ownership, especially open source, MySQL is generally selected as the site database for the development of small and medium-sized websites.


2. Reasons for selection

   * Support multiple platforms [AIX, FreeBSD, HP-UX, Linux, Mac OS, OpenBSD, Solaris, Windows...]

   * Support and provide multilingual API s

   * Open source, using GPL protocol, you can modify the source code to develop your own MySQL system

   * Support for standard SQL statements

   * Support multiple storage engines

   * Widespread use [MySQL is used for all but Microsoft's Live and Bing sites on the global top20 site]


3. MySQL Installation Method

   * Second Package Installation

   * Source Compilation Installation

   * Platform installation packages, such as rpm packages [centos,redhat] or deb[debian,ubuntu] packages


4. Environment [Turn off selinux]

[root@MySQL ~]# cat /etc/redhat-release 
CentOS release 6.9 (Final)

[root@MySQL ~]# uname -r
2.6.32-642.3.1.el6.x86_64

[root@MySQL ~]# hostname
MySQL

[root@MySQL ~]# getenforce 
Disabled


5.Installation [MySQL 5.7 is not installed the same way as MySQL 5.5/5.6]

   *Download MySQL 5.7 binary package [recommended for official download from MySQL]

[root@MySQL ~]# wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz


   *Unzip MySQL 5.7 binary package

[root@MySQL ~]# tar zxvf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz


   *Move MySQL 5.7 binary packages

[root@MySQL ~]# mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/


   *Create soft links

[root@MySQL ~]# ln -s /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/mysql


   *Create mysql user

[root@MySQL ~]# useradd -r -s /sbin/nologin mysql


   *Create MySQL data store directory

[root@MySQL ~]# mkdir -vp /data/mysql_data
mkdir: created directory `/data'
mkdir: created directory `/data/mysql_data'


   *Create mysql-files directory in MySQL binary package directory [MySQL data import/export data dedicated directory]

[root@MySQL ~]# mkdir -v /usr/local/mysql/mysql-files
mkdir: created directory `/usr/local/mysql/mysql-files'


   *Modify the user and group to which the MySQL binary package directory belongs

[root@MySQL ~]# chown root.mysql -R /usr/local/mysql-5.7.18-linux-glibc2.5-x86_64


   *Modify user and group belonging to MySQL data directory and data import/export dedicated directory

[root@MySQL ~]# chown mysql.mysql /usr/local/mysql/mysql-files /data/mysql_data


   *Rename without using the system's own MySQL profile/etc/my.cnf [Debian class system in/etc/mysql/my.cnf]

[root@MySQL ~]# mv /etc/my.cnf{,.old}


   *Initialization [Initialization completes with a random password in the output log]

     *Version smaller than MySQL 5.7.6 [< 5.7.6]

[root@MySQL ~]# /usr/local/mysql/bin/mysql_install_db \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/data/mysql_data

 

     *Version greater than or equal to MySQL 5.7.6 [>= 5.7.6]

* Initialize and specify the base directory and data store directory

[root@MySQL ~]# /usr/local/mysql/bin/mysqld --initialize \
--user=mysql \
--basedir=/usr/local/mysql \
--datadir=/data/mysql_data 
2017-06-23T20:13:52.827475Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-06-23T20:13:57.684349Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-06-23T20:13:58.435803Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-06-23T20:13:58.525266Z 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: 7d8f2b79-5850-11e7-9dab-000c29f0b169.
2017-06-23T20:13:58.538505Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-06-23T20:13:58.543606Z 1 [Note] A temporary password is generated for root@localhost: Z91g%.6d&fay

* Open an SSL connection 

[root@MySQL ~]# /usr/local/mysql/bin/mysql_ssl_rsa_setup --user=mysql \
--user=mysql \
--basedir=/usr/local/mysql \

6. Create startup scripts

   *Copy startup script to service service service management directory [/etc/init.d]

[root@MySQL ~]# cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld


   *Modify MySQL startup script [/et/init.d/mysql D]

basedir=    ==> basedir=/usr/local/mysql
datadir=    ==> datadir=/data/mysql_data


   *Add script execution privileges

[root@MySQL ~]# chmod +x /etc/init.d/mysqld


   *Add to service Service service Management

[root@MySQL ~]# chkconfig --add mysqld


7. Service Startup Test

   * Start MySQL service

[root@MySQL ~]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/data/mysql_data/MySQL.err'.
.. SUCCESS!


   * Check to see if the service starts and listens on the port [default 3306]

[root@MySQL ~]# netstat -lntp | grep 3306
tcp        0      0 :::3306             :::*                LISTEN      20896/mysqld


8. Service Startup Test

   * Connect via the built-in mysql client [using the random password output at initialization]

[root@MySQL ~]# /usr/local/mysql/bin/mysql -p'Z91g%.6d&fay'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
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>

   *Change password

mysql> set password = '123456';
Query OK, 0 rows affected (0.00 sec)

   *Reuse password connection

mysql> quit
Bye
[root@MySQL ~]# /usr/local/mysql/bin/mysql -p'123456'
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.18 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>



9. Summary


With demand-driven technology, technology itself has no advantages but only business.

Topics: MySQL Oracle Linux Database