选择通用型二进制安装包,下载地址:https://downloads.mysql.com/archives/community/
我这边选择的5.7.19版本,对应的安装包为:mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
[root@cnsz92vl13410 ~]# groupadd mysql
[root@cnsz92vl13410 ~]# useradd mysql -g mysql
[root@cnsz92vl13410 ~]# passwd mysql
Changing password for user mysql.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
[root@cnsz92vl13410 ~]#lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 60G 0 disk
├─vda1 252:1 0 476M 0 part /boot
└─vda2 252:2 0 59.5G 0 part
├─vg00-root 253:0 0 10G 0 lvm /
├─vg00-home 253:1 0 500M 0 lvm /home
├─vg00-var 253:2 0 10G 0 lvm /var
├─vg00-tmp 253:3 0 10G 0 lvm /tmp
└─vg00-app 253:4 0 29G 0 lvm /app
vdb 252:16 0 50G 0 disk
[root@cnsz92vl13410 /]# printf "n\np\n1\n\n\nw\n" | fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x5caa62eb.
Command (m for help): Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): Partition number (1-4, default 1): First sector (2048-104857599, default 2048): Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): Using default value 104857599
Partition 1 of type Linux and of size 50 GiB is set
Command (m for help): The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@cnsz92vl13410 /]# pvcreate /dev/vdb1
Physical volume "/dev/vdb1" successfully created
[root@cnsz92vl13410 /]# vgcreate vg01 /dev/vdb1
Volume group "vg01" successfully created
[root@cnsz92vl13410 /]# lvcreate -L 49G -n LVdata vg01
Logical volume "LVdata" created.
[root@cnsz92vl13410 /]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
[root@cnsz92vl13410 /]# mkfs.xfs /dev/mapper/vg01-LVdata
meta-data=/dev/mapper/vg01-LVdata isize=512 agcount=4, agsize=3211264 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=12845056, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=6272, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@cnsz92vl13410 /]# echo "/dev/mapper/vg01-LVdata /dbdata xfs defaults 0 0" >> /etc/fstab
[root@cnsz92vl13410 /]# mount -a
mount: mount point /dbdata does not exist
[root@cnsz92vl13410 /]# mkdir /dbdata
[root@cnsz92vl13410 /]# mount -a
[root@cnsz92vl13410 /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg00-root 10G 1.4G 8.7G 14% /
devtmpfs 3.9G 0 3.9G 0% /dev
tmpfs 3.9G 0 3.9G 0% /dev/shm
tmpfs 3.9G 17M 3.9G 1% /run
tmpfs 3.9G 0 3.9G 0% /sys/fs/cgroup
/dev/mapper/vg00-var 10G 240M 9.8G 3% /var
/dev/vda1 473M 173M 301M 37% /boot
/dev/mapper/vg00-home 497M 26M 472M 6% /home
/dev/mapper/vg00-app 30G 420M 29G 2% /app
/dev/mapper/vg00-tmp 10G 33M 10G 1% /tmp
tmpfs 783M 0 783M 0% /run/user/800
/dev/mapper/vg01-LVdata 49G 33M 49G 1% /dbdata
[root@cnsz92vl13410 /]# chown -R mysql:mysql /dbdata/
[root@cnsz92vl13410 /]# su - mysql
Last login: Mon Aug 17 11:17:18 CST 2020 on pts/1
[root@cnsz92vl13410 app]# ls -lrt
total 625640
drwxr-xr-x 8 mwop mwop 4096 Nov 29 2017 jdk1.8.0_121
drwxr-xr-x 9 mwop mwop 149 Jan 22 2018 apache-tomcat-7.0.75
-rw-r--r-- 1 root root 640650826 May 16 2019 mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
[root@cnsz92vl13410 app]# mkdir mysql
[root@cnsz92vl13410 app]# ls
apache-tomcat-7.0.75 jdk1.8.0_121 mysql mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
[root@cnsz92vl13410 app]# chown -R mysql:mysql mysql
[root@cnsz92vl13410 app]# ls -lrt
total 625640
drwxr-xr-x 8 mwop mwop 4096 Nov 29 2017 jdk1.8.0_121
drwxr-xr-x 9 mwop mwop 149 Jan 22 2018 apache-tomcat-7.0.75
-rw-r--r-- 1 root root 640650826 May 16 2019 mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz
drwxr-xr-x 2 mysql mysql 6 Aug 17 11:30 mysql
[root@cnsz92vl13410 app]# tar -xvf mysql-5.7.19-linux-glibc2.12-x86_64.tar.gz -C mysql
[root@cnsz92vl13410 app]# cd mysql/
[root@cnsz92vl13410 mysql]# ls
mysql-5.7.19-linux-glibc2.12-x86_64
[root@cnsz92vl13410 mysql]# mv mysql-5.7.19-linux-glibc2.12-x86_64/ 5.7.19
[root@cnsz92vl13410 mysql]# ls
5.7.19
[root@cnsz92vl13410 mysql]# cd 5.7.19/
[root@cnsz92vl13410 5.7.19]# ls
bin COPYING docs include lib man README share support-files
[root@cnsz92vl13410 5.7.19]# su - mysql
Last login: Mon Aug 17 11:28:16 CST 2020 on pts/1
[mysql@cnsz92vl13410 ~]$ cd /dbdata/
[mysql@cnsz92vl13410 dbdata]$ ls
[mysql@cnsz92vl13410 dbdata]$ mkdir my5000
[mysql@cnsz92vl13410 dbdata]$ cd my5000/
[mysql@cnsz92vl13410 my5000]$ ls
[mysql@cnsz92vl13410 my5000]$ cd /app/mysql/
[mysql@cnsz92vl13410 mysql]$ ls
5.7.19
[mysql@cnsz92vl13410 mysql]$ cd 5.7.19/
[mysql@cnsz92vl13410 5.7.19]$ ls
bin COPYING docs include lib man README share support-files
[mysql@cnsz92vl13410 5.7.19]$ cd /dbdata/
[mysql@cnsz92vl13410 dbdata]$ ls
my5000
[mysql@cnsz92vl13410 dbdata]$ cd my5000/
[mysql@cnsz92vl13410 my5000]$ ls
[mysql@cnsz92vl13410 my5000]$ mkdir data tmp var log
[mysql@cnsz92vl13410 my5000]$ ls
data log tmp var
[client]
socket = /dbdata/my5000/var/mysql.sock
port = 5000
[mysqld]
############# GENERAL #############
autocommit = ON
character_set_server = UTF8MB4
collation_server = UTF8MB4_bin
explicit_defaults_for_timestamp = ON
lower_case_table_names = 1
read_only = OFF
transaction_isolation = READ-COMMITTED
####### CACHES AND LIMITS #########
interactive_timeout = 600
max_allowed_packet = 32M
max_connect_errors = 10000
max_connections = 300
max_user_connections = 200
sort_buffer_size = 1M
table_definition_cache = 1400
table_open_cache = 2000
table_open_cache_instances = 4
thread_cache_size = 9
thread_stack = 256K
tmp_table_size = 32M
############# SAFETY ##############
local_infile = OFF
skip_name_resolve = ON
sql_mode = STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ONLY_FULL_GROUP_BY
############# LOGGING #############
general_log = 0
log_queries_not_using_indexes = ON
log_slow_admin_statements = ON
log_error_verbosity = 2
long_query_time = 1
slow_query_log = ON
############# REPLICATION #############
binlog_checksum = CRC32
binlog_format = row
binlog_rows_query_log_events = ON
enforce_gtid_consistency = ON
expire_logs_days = 7
gtid_mode = ON
log_slave_updates = ON
master_info_repository = TABLE
master_verify_checksum = ON
max_binlog_size = 32M
relay_log_info_repository = TABLE
server_id = 1
skip_slave_start = ON
slave_net_timeout = 4
slave_sql_verify_checksum = ON
sync_binlog = 0
sync_master_info = 10000
sync_relay_log = 10000
sync_relay_log_info = 10000
############### PATH ##############
basedir = /app/mysql/5.7.19
datadir = /dbdata/my5000/data
tmpdir = /dbdata/my5000/tmp
socket = /dbdata/my5000/var/mysql.sock
pid_file = /dbdata/my5000/var/mysql.pid
innodb_data_home_dir = /dbdata/my5000/data
log_error = /dbdata/my5000/log/error.log
general_log_file = /dbdata/my5000/log/general.log
slow_query_log_file = /dbdata/my5000/log/slow.log
log_bin = /dbdata/my5000/log/mysql-bin
log_bin_index = /dbdata/my5000/log/mysql-bin.index
relay_log = /dbdata/my5000/log/relay-log
relay_log_index = /dbdata/my5000/log/relay-log.index
############# INNODB #############
innodb_file_format = barracuda
innodb_flush_method = O_DIRECT
innodb_buffer_pool_size = 1G
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_flush_log_at_trx_commit = 2
innodb_support_xa = ON
innodb_strict_mode = ON
innodb_data_file_path = ibdata1:12M;ibdata2:16M:autoextend
innodb_checksum_algorithm = strict_crc32
[mysql]
############# CLIENT #############
max_allowed_packet = 32M
socket = /dbdata/my5000/var/mysql.sock
[mysqldump]
max_allowed_packet = 32M
[mysql@cnsz92vl13410 my5000]$ /app/mysql/5.7.19/bin/mysqld --initialize --basedir=/app/mysql/5.7.19 --datadir=/dbdata/my5000/data --user=mysql --explicit_defaults_for_timestamp
2020-08-17T06:28:36.680355Z 0 [Warning] InnoDB: New log files created, LSN=45790
2020-08-17T06:28:36.872112Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2020-08-17T06:28:36.940342Z 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: e1db3d7f-e052-11ea-ab65-fa163e4abd11.
2020-08-17T06:28:36.944968Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-08-17T06:28:36.945632Z 1 [Note] A temporary password is generated for root@localhost: ***z2ckh=fBekKf***
[mysql@cnsz92vl13410 my5000]$ /app/mysql/5.7.19/bin/mysqld_safe --defaults-file=/dbdata/my5000/my.cnf &
[1] 19871
[mysql@cnsz92vl13410 my5000]$ 2020-08-17T06:28:55.012412Z mysqld_safe Logging to '/dbdata/my5000/log/error.log'.
2020-08-17T06:28:55.041869Z mysqld_safe Starting mysqld daemon with databases from /dbdata/my5000/data
[mysql@cnsz92vl13410 my5000]$
[mysql@cnsz92vl13410 my5000]$
[mysql@cnsz92vl13410 my5000]$ ps -ef|grep mysql
root 10687 2389 0 14:08 pts/1 00:00:00 su - mysql
mysql 10688 10687 0 14:08 pts/1 00:00:00 -bash
mysql 19871 10688 0 14:28 pts/1 00:00:00 /bin/sh /app/mysql/5.7.19/bin/mysqld_safe --defaults-file=/dbdata/my5000/my.cnf
mysql 20778 19871 13 14:28 pts/1 00:00:01 /app/mysql/5.7.19/bin/mysqld --defaults-file=/dbdata/my5000/my.cnf --basedir=/app/mysql/5.7.19 --datadir=/dbdata/my5000/data --plugin-dir=/app/mysql/5.7.19/lib/plugin --log-error=/dbdata/my5000/log/error.log --pid-file=/dbdata/my5000/varmysql.pid --socket=/dbdata/my5000/var/mysql.sock
mysql 20816 10688 0 14:29 pts/1 00:00:00 ps -ef
mysql 20817 10688 0 14:29 pts/1 00:00:00 grep --color=auto mysql
[mysql@cnsz92vl13410 ~]$ /app/mysql/5.7.19/bin/mysql -uroot --socket=/dbdata/my5000/var/mysql.sock -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.19-log
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> alter user 'root'@'localhost' identified by 'XXXXXXXXX';
Query OK, 0 rows affected (0.00 sec)
[mysql@cnsz92vl13410 ~]$ ln -s /dbdata/my5000/var/mysql.sock /tmp/mysql.sock
[mysql@cnsz92vl13410 ~]$ /app/mysql/5.7.19/bin/mysql_secure_installation --defaults-file=/dbdata/my5000/my.cnf
[mysql@cnsz92vl13410 ~]$ rm /tmp/mysql.sock
[mysql@cnsz92vl13410 ~]$ /app/mysql/5.7.19/bin/mysql_config_editor set --login-path=root --user=root --password
Enter password:
[mysql@cnsz92vl13410 ~]$ /app/mysql/5.7.19/bin/mysql -uroot --socket=/dbdata/my5000/var/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.19-log 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>