--- mySQL installation process of installing binary and source code

Install mysql


Source package installation


Optimization of the underlying source

[root@db03 ~]# vim /etc/yum.repos.d/CentOS-Base.repo 

Installation dependencies

[root@db03 ~]# yum install -y cmake ncurses-devel autoconf

Download (or upload):

wget https://downloads.mysql.com/archives/get/file/mysql-5.6.44.tar.gz

Decompression:

[root@db03 ~]# tar xf mysql-5.6.44.tar.gz 
[root@db03 ~]# cd mysql-5.6.44
[root@db03 ~/mysql-5.6.44]# ll
total 252
drwxr-xr-x  2 7161 31415  4096 Mar 15  2019 BUILD
drwxr-xr-x  2 7161 31415  4096 Mar 15  2019 client
drwxr-xr-x  4 7161 31415  4096 Mar 15  2019 cmake
-rw-r--r--  1 7161 31415 23415 Mar 15  2019 CMakeLists.txt
drwxr-xr-x  3 7161 31415    21 Mar 15  2019 cmd-line-utils
-rw-r--r--  1 7161 31415 19838 Mar 15  2019 config.h.cmake
-rw-r--r--  1 7161 31415 40929 Mar 15  2019 configure.cmake
-rw-r--r--  1 7161 31415 17987 Mar 15  2019 COPYING
drwxr-xr-x  2 7161 31415   312 Mar 15  2019 dbug
drwxr-xr-x  2 7161 31415    80 Mar 15  2019 Docs
-rw-r--r--  1 7161 31415 65958 Mar 15  2019 Doxyfile-perfschema
drwxr-xr-x  4 7161 31415   229 Mar 15  2019 extra
drwxr-xr-x  4 7161 31415  4096 Mar 15  2019 include
-rw-r--r--  1 7161 31415   333 Mar 15  2019 INSTALL
drwxr-xr-x  3 7161 31415   224 Mar 15  2019 libmysql
drwxr-xr-x  3 7161 31415   204 Mar 15  2019 libmysqld
drwxr-xr-x  2 7161 31415   221 Mar 15   2019 libservices
drwxr-xr-x   2 7161 31415   4096 Mar 15   2019 man
drwxr-xr-x 10 7161 31415   305 Mar 15   2019 mysql-test
drwxr-xr-x   2 7161 31415   4096 Mar 15   2019 mysys
drwxr x--XR   2 7161 31415   300 Mar 15   2019 mysys_ssl
drwxr-xr-x   9 7161 31415   113 Mar 15   2019 packaging
drwxr-xr-x11 7161 31415   187 Mar 15  2019 plugin
-rw-r--r--  1 7161 31415  2496 Mar 15  2019 README
drwxr-xr-x  2 7161 31415  4096 Mar 15  2019 regex
drwxr-xr-x  2 7161 31415  4096 Mar 15  2019 scripts
drwxr-xr-x  2 7161 31415     6 Mar 15  2019 source_downloads
drwxr-xr-x  4 7161 31415 12288 Mar 15  2019 sql
drwxr-xr-x  5 7161 31415  4096 Mar 15  2019 sql-bench
drwxr-xr-x  2 7161 31415   155 Mar 15  2019 sql-common
drwxr-xr-x 13 7161 31415   169 Mar 15  2019 storage
drwxr-xr-x  2 7161 31415  4096 Mar 15  2019 strings
drwxr-xr-x  5 7161 31415  4096 Mar 15  2019 support-files
drwxr-xr-x  2 7161 31415  4096 Mar 15  2019 tests
drwxr-xr-x  5 7161 31415    70 Mar 15  2019 unittest
-rw-r--r--  1 7161 31415    88 Mar 15  2019 VERSION
drwxr-xr-x  3 7161 31415   298 Mar 15  2019 vio
drwxr-xr-x  2 7161 31415    32 Mar 15  2019 win
drwxr-xr-x 11 7161 31415  4096 Mar 15  2019 zlib

Determine the installation path exists does not exist, does not exist, create /opt/mysql-5.6.44:

[root@db03 ~/mysql-5.6.44]# ll /opt/ -d
drwxr-xr-x. 2 root root 6 Apr 11  2018 /opt/

Generation:

[root@db03 ~/mysql-5.6.44]# “注意必须在此目录里面进行生成”
cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql-5.6.44 \
-DMYSQL_DATADIR=/opt/mysql-5.6.44/data \
-DMYSQL_UNIX_ADDR=/opt/mysql-5.6.44/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITH_ZLIB=bundled \
-DWITH_SSL=bundled \
-DENABLED_LOCAL_INFILE = 1 \
-DWITH_EMBEDDED_SERVER = 1 \
-DENABLE_DOWNLOADS = 1 \
-DWITH_DEBUG = 0 # inspection after the build is complete [root @ DB03 ~ / MySQL-5.6.44] # echo $?   Equal to 0 no problem




Compile:

[root@db03 ~/mysql-5.6.44]# make

installation:

[root@db03 ~/mysql-5.6.44]# make install

#检查
[root@db03 ~/mysql-5.6.44]# ll /opt/mysql-5.6.44/
total 44
drwxr-xr-x  2 root root  4096 Oct 31 03:53 bin
-rw-r--r--  1 root root 17987 Mar 15  2019 COPYING
drwxr-xr-x  3 root root    18 Oct 31 03:53 data
drwxr-xr-x  2 root root    55 Oct 31 03:53 docs
drwxr-xr-x  3 root root  4096 Oct 31 03:53 include
drwxr-xr-x  3 root root   291 Oct 31 03:53 lib
drwxr-xr-x  4 root root    30 Oct 31 03:53 man
drwxr-xr-x 10 root root  4096 Oct 31 03:53 mysql-test
-rw-r--r--  1 root root  2496 Mar 15  2019 README
drwxr-xr-x  2 root root    30 Oct 31 03:53 scripts
drwxr-xr-x 28 root root  4096 Oct 31 03:53 share
drwxr-xr-x  4 root root  4096 Oct 31 03:53 sql-bench
drwxr-xr-x  2 root root   136 Oct 31 03:53 support-files

Create a user

[root@db03 ~/mysql-5.6.44]# useradd mysql -s /sbin/nologin -M
[root@db03 ~/mysql-5.6.44]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)

Copy startup script

[root@db03 ~/mysql-5.6.44]# cd /opt/mysql-5.6.44/support-files/
[root@db03 /opt/mysql-5.6.44/support-files]# cp mysql.server /etc/init.d/mysqld
[root@db03 /opt/mysql-5.6.44/support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10571 Oct 31 03:57 /etc/init.d/mysqld

Copy the configuration file (on the cover exists, does not exist, create)

[root@db03 /opt/mysql-5.6.44/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y

Create a socket file storage directory

[root@db03 /opt/mysql-5.6.44/support-files]# mkdir /opt/mysql-5.6.44/tmp
[root@db03 /opt/mysql-5.6.44/support-files]# ll /opt/mysql-5.6.44/tmp -d
drwxr-xr-x 2 root root 6 Oct 31 03:59 /opt/mysql-5.6.44/tmp

Production of soft link

[root@db03 /opt/mysql-5.6.44/support-files]# cd /opt/mysql-5.6.44/scripts/
[root@db03 /opt/mysql-5.6.44/scripts]# ll
total 36
-rwxr-xr-x 1 root root 34558 Oct 31 03:31 mysql_install_db
[root@db03 /opt/mysql-5.6.44/scripts]# ln -s /opt/mysql-5.6.44/ /opt/mysql
[root@db03 /opt/mysql-5.6.44/scripts]# ll /opt/mysql
lrwxrwxrwx 1 root root 18 Oct 31 04:01 /opt/mysql -> /opt/mysql-5.6.44/

Authorize

[root@db03 /opt/mysql-5.6.44/scripts]# chown -R mysql.mysql /opt/*

Initialize the database

[root@db03 /opt/mysql-5.6.44/scripts]# ./mysql_install_db --user=mysql --basedir=/opt/mysql --datadir=/opt/mysql/data

Start mysql service

[root@db03 /opt/mysql-5.6.44/scripts]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

Adding Environment Variables

[root@db03 /opt/mysql-5.6.44/scripts]# vim /etc/profile.d/mysql.sh
export PATH="/opt/mysql/bin:$PATH"

[root@db03 /opt/mysql-5.6.44/scripts]# source /etc/profile.d/mysql.sh

Port Check

[root@db03 /opt/mysql-5.6.44/scripts]# netstat -lntup |grep 3306
tcp6       0      0 :::3306                 :::*                   LISTEN      25084/mysqld

Start the database

[root@db03 /opt/mysql-5.6.44/scripts]# mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.44 Source distribution

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>

Permission to change mysql start and join systemd management

vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000

The mysql join systemd management, and adding boot from Kai

[root@db01 ~]#  vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf  ---------------注意安装路径
LimitNOFILE = 5000

[root@db01 ~]# systemctl start mysqld
[root@db01 ~]# systemctl stop mysqld
[root@db01 ~]# systemctl enable mysqld

 


Binary install mysql


Download or upload software packages

wget https://downloads.mysql.com/archives/get/file/mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz

Decompression

[root@db04 ~]# tar xf mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz 
[root@db04 ~]# ll
total 321404
drwxr-xr-x  13 root root       191 Oct 31 04:31 mysql-5.6.44-linux-glibc2.12-x86_64
-rw-r--r--   1 root root 329105487 Oct 30 10:23 mysql-5.6.44-linux-glibc2.12-x86_64.tar.gz

Installation depends Packages

[root@db04 ~]# yum install -y autoconf libaio*

Create a mysql user

[root@db04 ~]# useradd mysql -s /sbin/nologin -M
[root@db04 ~]# id mysql
uid=1000(mysql) gid=1000(mysql) groups=1000(mysql)

After extracting the package directory to / opt directory and change the file name

[root@db04 ~]# mv mysql-5.6.44-linux-glibc2.12-x86_64 /opt/mysql-5.6.44
[root@db04 ~]# cd /opt/mysql-5.6.44/
[root@db04 /opt/mysql-5.6.44]# ll
total 40
drwxr-xr-x  2 root root   4096 Oct 31 04:31 bin
-rw-r--r--  1 7161 31415 17987 Mar 15  2019 COPYING
drwxr-xr-x  3 root root     18 Oct 31 04:30 data
drwxr-xr-x  2 root root     55 Oct 31 04:30 docs
drwxr-xr-x  3 root root   4096 Oct 31 04:30 include
drwxr-xr-x  3 root root    316 Oct 31 04:31 lib
drwxr-xr-x  4 root root     30 Oct 31 04:30 man
drwxr-xr-x 10 root root    291 Oct 31 04:30 mysql-test
-rw-r--r--  1 7161 31415  2496 Mar 15  2019 README
drwxr-xr-x  2 root root     30 Oct 31 04:30 scripts
drwxr-xr-x 28 root root   4096 Oct 31 04:31 share
drwxr-xr-x  4 root root   4096 Oct 31 04:31 sql-bench
drwxr-xr-x  2 root root    136 Oct 31 04:30 support-files

Production of soft link

[root@db04 ~]# ln -s /opt/mysql-5.6.44/ /opt/mysql
[root@db04 ~]# ll /opt/mysql
lrwxrwxrwx 1 root root 18 Oct 31 04:37 /opt/mysql -> /opt/mysql-5.6.44/

Copy startup script

[root@db04 /opt/mysql-5.6.44]# cd /opt/mysql-5.6.44/support-files/
[root@db04 /opt/mysql-5.6.44/support-files]# cp mysql.server /etc/init.d/mysqld
[root@db04 /opt/mysql-5.6.44/support-files]# ll /etc/init.d/mysqld
-rwxr-xr-x 1 root root 10565 Oct 31 04:40 /etc/init.d/mysqld

Copy the configuration file

[root@db04 /opt/mysql-5.6.44/support-files]# cp my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y
[root@db04 /opt/mysql-5.6.44/support-files]# ll /etc/my.cnf
-rw-r--r--. 1 root root 1126 Oct 31 04:41 /etc/my.cnf

Initialize the database

[root@db04 /opt/mysql-5.6.44/support-files]# cd ../scripts/
[root@db04 /opt/mysql-5.6.44/scripts]# ll
total 36
-rwxr-xr-x 1 7161 31415 34558 Mar 15  2019 mysql_install_db
[root@db04 /opt/mysql-5.6.44/scripts]# ./mysql_install_db --basedir=/opt/mysql --datadir=/opt/mysql/data --user=mysql

Authorization mysql directory

[root@db04 /opt/mysql-5.6.44/scripts]# chown -R mysql.mysql /opt/*
[root@db04 /opt/mysql-5.6.44/scripts]# ll /opt/
total 0
lrwxrwxrwx  1 mysql mysql  18 Oct 31 04:37 mysql -> /opt/mysql-5.6.44/
drwxr-xr-x 13 mysql mysql 223 Oct 31 04:43 mysql-5.6.44

Mysql modify the startup scripts and procedures

[root@db04 /opt/mysql-5.6.44/scripts]# sed -i 's#/usr/local#/opt#g' /etc/init.d/mysqld /opt/mysql/bin/mysqld_safe

Start mysqkl

[root@db04 /opt/mysql-5.6.44/scripts]# /etc/init.d/mysqld start
Starting MySQL.Logging to '/opt/mysql/data/db04.err'.
 SUCCESS!

Adding Environment Variables

[root@db04 /opt/mysql-5.6.44/scripts]# vim /etc/profile.d/mysql.sh
export PATH="/opt/mysql/bin:$PATH"
[root@db04 /opt/mysql-5.6.44/scripts]# source /etc/profile.d/mysql.sh

Log in mysql database

[root@db04 /opt/mysql-5.6.44/scripts]# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.44 MySQL Community Server (GPL)

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> 

The mysql join systemd management, and adding boot from Kai

[root@db01 ~]#  vim /usr/lib/systemd/system/mysqld.service
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/opt/mysql/bin/mysqld --defaults-file=/etc/my.cnf  ---------------注意安装路径
LimitNOFILE = 5000

------------------------
[root@db04 ~]# vim /etc/my.cnf

basedir = /opt/mysql        ----------------------更改此处
datadir = /opt/mysql/data   ----------------------更改此处

----------------------------

[root@db01 ~]# systemctl start mysqld
[root@db01 ~]# systemctl stop mysqld
[root@db01 ~]# systemctl enable mysqld

 

 

Guess you like

Origin www.cnblogs.com/daiyacheng1991/p/11779242.html