Centos 7.2 Compile and Install Mysql 5.7.18 Configuration and Details

Posted by mcubedma on Tue, 14 May 2019 23:09:50 +0200

I. Main features of MySQL 5.7

(1) Native Support Systemd

(2) Better performance: for multi-core CPU, solid-state hard disk, lock has better optimization

(3) Better InnoDB storage engine

(4) More robust replication: replication brings a solution that data is not lost at all. Traditional financial customers can also use mysql database.

(5) Added sys Library: This will be the most frequently accessed library by DBA in the future

(6.) Better optimizer: The significance of optimizer code refactoring will bring tremendous improvements in this and future versions. Oracle is officially addressing the biggest problem before mysql, native JSON type support (JavaScript object Notation)

Note: JSON (JavaScript Object Notation) is a lightweight data exchange format. JSON uses language-independent text formats, but also uses habits similar to the C language family (including c, c++, c#, java, JavaScript, Perl, Python, etc.). These features make JSON an ideal data exchange language. Easy to read and write, but also easy to machine parse and generation (generally used to improve network transmission rate).

Data in key-value pairs

Data is separated by commas

Curly brackets save objects

Square brackets save data

Installation of MySQL 5.7.18

1. System environment: centos7.2 x86_64

[root@kang ~]# uname -r
3.10.0-327.el7.x86_64
[root@kang ~]# cat  /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
Because CentOS 7.2 installs mariadb-libs by default, all must be uninstalled first, if not uninstalled, the installation will be wrong.

Also avoid unnecessary files that have been generated by installing mariadb-libs.

First check to see if mariadb-libs are installed

[root@kang ~]# rpm  -qa | grep  mariadb-libs
mariadb-libs-5.5.44-2.el7.centos.x86_64
Uninstall mariadb-libs

   

[root@kang ~]# rpm  -e  mariadb-libs --nodeps
2. Install mysql-related dependency packages

The role of dependency packages:

  • CMake: Since the conventional configure compilation method has been abandoned since version 5.5 of mysql, a CMake compiler is needed to set the compilation parameters of mysql. Such as: installation directory, data storage directory, character encoding, sorting rules, etc.
  • Boost: Starting with mysql 5.7.5, boost libraries are necessary. c++ boost libraries are used in mysql source code, requiring boost 1.59.0 or more to be installed.
  • GCC is a C language compiling tool under Linux. The source code of mysql is compiled entirely by C and c++. It is required to install GCC.
  • Bion: C/C++ Parser under Linux
  • ncurses: Character Terminal Processing Library

Installation file preparation:

Download cmake-3.5.tar.gz.Download address: http://www.cmake.org/download/
Download ncurses-5.9.tar.gz. Download address: ftp://ftp.gnu.org/gnu/ncurese/

Download bison-3.0.4.tar.gz. Download address: ftp://ftp.gnu.org/gnu/bison/

Download mysql-5.7.18.tar.gz

Download address: wget http://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.18.tar.gz

Download Boost_1_59_0.tar.gz

wget  http://nchc.dl.sourceforge.net/project/boost/boosst/1.5.9.0/boost_1_59_0.tar.gz

(1) Install cmake

[root@kang ~]# tar zxf  cmake-3.5.2.tar.gz 
[root@kang ~]# cd cmake-3.5.2/
[root@kang cmake-3.5.2]# ./bootstrap 

[root@kang cmake-3.5.2]# gmake && gmake install 

cmake  -version #View cmake version information

(2) Install ncurses

[root@kang ~]# tar zxf ncurses-5.9.tar.gz 
[root@kang ~]# cd ncurses-5.9/
[root@kang ncurses-5.9]# ./configure && make && make install

(3) Installation of bison

[root@kang ~]# tar zxf bison-3.0.4.tar.gz 
[root@kang ~]# cd  bison-3.0.4/
[root@kang bison-3.0.4]# ./configure && make && make install

(4) Install boost

[root@kang ~]# tar zxf boost_1_59_0.tar.gz 
[root@kang ~]# mv boost_1_59_0 /usr/local/boost
(5) Create mysql users and groups and related directories

[root@kang ~]# groupadd  -r mysql && useradd -r -g mysql -s /bin/false -M mysql 
[root@kang ~]# mkdir /usr/local/mysql
[root@kang ~]# mkdir /usr/local/mysql/data
(6.) Compile and install mysql

Decompress the source code package:

[root@kang ~]# tar zxf mysql-5.7.18.tar.gz 
[root@kang ~]# cd mysql-5.7.18/
[root@kang mysql-5.7.18]# 
Execute the cmake command to configure before compilation:

[root@kang mysql-5.7.18]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_SYSTEMD=1 -DWITH_BOOST=/usr/local/boost

Start compiling and installing:

[root@kang mysql-5.7.18]# make && make install 


Note: Detailed configuration parameters:

- Root directory of DCMAKE_INSTALL_PREFIX=/usr/local/mysql#mysql installation

- DMYSQL_DATADIR=/usr/local/mysql/data#mysql database file storage directory

- The directory where the DSYSCONFDIR=/etc#mysql configuration file is located

- DWITH_MYISAM_STORAGE_ENGINE=1 # Add MYISAM Engine Support

- DWITH_INNOBASE_STORAGE_ENGINE=1 # Add InnoDB Engine Support

- DWITH_ARCHIVE_STORAGE_ENGINE=1 # Add ARCHIVE Engine Support

- DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock# Specifies the location of mysql.sock

- DWITH_PARTITION_STORAGE_ENGINE=1# Installation Support Database Partition

- DEXTRA_CHARSETS=all # Make mysql support all extended characters

- DDEFAULT_CHARSET=utf8 # Sets the default character set of mysql to utf8

- DDEFAULT_COLLATION=utf8_general_ci Sets default character set proofreading rules

- DWITH-SYSTEMD=1# You can use system D to control mysql services

- DWITH_BOOST=/usr/local/boost# points to the directory where the boost library is located

(7) Setting environmental variables

[root@kang ~]# echo "export PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
[root@kang ~]# source /etc/profile
(8) Set relevant permissions for mysql data directory files

[root@kang ~]# chown  -R  mysql:mysql  /usr/local/mysql/
[root@kang ~]# cd /usr/local/mysql/
[root@kang mysql]# chmod  755  data/
(9.) Initialize mysql database

[root@kang mysql]# cd /usr/local/mysql/
[root@kang mysql]# mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

(10) Create and modify mysql master configuration file

[root@kang ~]# cd /usr/local/mysql/
[root@kang mysql]# vim /etc/my.cnf
[client]
socket=/usr/local/mysql/mysql.sock
[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
socket=/usr/local/mysql/mysql.sock
log-error=/usr/local/mysql/data/mysqld.err
~
Note: Rescan system D to scan new or changed units

[root@kang mysql]# systemctl daemon-reload 
(11.) Configure mysql autostart

[root@kang mysql]# cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service  /usr/lib/systemd/system
mysql database service failed to start!

[root@kang mysql]# systemctl  start mysqld
Job for mysqld.service failed because the control process exited with error code. See "systemctl status mysqld.service" and "journalctl -xe" for details.
View the error log file:

Through the above error discovery, in mysqld.service, the default pid file is assigned to / var/run/mysqld / directory, but the directory is not established beforehand, so it is necessary to establish the directory manually and assign permissions to mysql users, so that there will be no misreporting!!

[root@kang ~]# mkdir /var/run/mysqld
[root@kang ~]# chown  -R  mysql:mysql /var/run/mysqld/
#systemctl  daemon-reload
Start the mysql service again:

View the port number:

Access mysql database:

mysql -uroot -p YGyr8jr=?,Ta       #Get the temporary password and go to the data directory to view cat mysqld.err | grep password in this way 

(12) Setting the password of database administrator user root

[root@kang ~]# mysqladmin  -uroot -p password 'pwd123'
Enter password: 



Here you are, mysql-5.7.18 database is installed at this point!! _____________

Hope to help you!!    

Installation process is a bit long to wait patiently!!  


























Topics: MySQL cmake Database MariaDB