欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

编译安装自定义目录MySQL5.7

程序员文章站 2022-06-21 21:00:03
...
1. 构建环境
yum -y groupinstall "Development Tools"
yum -y install ruby ruby-devel rubygems gcc openssl-devel

2. 安装FPM
gem sources --add http://mirrors.aliyun.com/rubygems/ --remove http://rubygems.org/
gem install arr-pm fpm


3. 编译安装
yum install libaio-devel ncurses-devel libgcrypt perl make cmake gcc gcc-c++ bison -y

mkdir -p /data/{download,rpms/mysql-5.7.20}
cd /data/download
tar zxf mysql-5.7.20.tar.gz
tar zxf boost_1_59_0.tar.gz
cd mysql-5.7.20

export DIR_SRC_INSTALL=/data/rpms/mysql-5.7.20
export DIR_SRC_BOOST=/data/download/boost_1_59_0
export DIR_RPM_INSTALL=/opt/swancmp/mysql
export DIR_RPM_DATA=/opt/swancmp/mysql/mysql
export LDFLAGS="-Wl,-rpath=${DIR_PY_RPM_INSTALL}/lib ${LDFLAGS}"

groupadd -g 27 -o -r mysql >/dev/null 2>&1 || :
useradd -M -N -g mysql -o -r -d ${DIR_RPM_DATA} -s /bin/false -c "MySQL Server" -u 27 mysql >/dev/null 2>&1 || :
mkdir -p /opt/swancmp/mysql/{mysql,log,tmp}
chown -R mysql:mysql /opt/swancmp/mysql/mysql/

cmake -DCMAKE_INSTALL_PREFIX=${DIR_RPM_INSTALL} \
-DMYSQL_DATADIR=${DIR_RPM_DATA} \
-DWITH_BOOST=${DIR_SRC_BOOST} \
-DSYSCONFDIR=${DIR_RPM_INSTALL} \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DENABLED_LOCAL_INFILE=1 \
-DENABLE_DTRACE=0 \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_bin \
-DWITH_EMBEDDED_SERVER=1

make

make install DESTDIR=${DIR_SRC_INSTALL}



4. 打包前准备
vi /data/rpms/mysql-5.7.20/opt/swancmp/mysql/my.cnf
[client]
default-character-set=utf8
# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html

[mysqld]
character-set-server=utf8
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
basedir=/opt/swancmp/mysql
datadir=/opt/swancmp/mysql/mysql
tmpdir=/opt/swancmp/mysql/tmp
socket=/tmp/mysql.sock

port=3307

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-error=/opt/swancmp/mysql/log/mysqld.log
pid-file=/opt/swancmp/mysql/run/mysqld/mysqld.pid
# validate_password = off,取消MySQL强制密码规则校验设置
validate_password=off
max_connections=32000


vi /opt/before_install.sh
#!/bin/bash

groupadd -g 27 -o -r mysql >/dev/null 2>&1 || :
useradd -M -N -g mysql -o -r -d /opt/swancmp/mysql/mysql -s /bin/false -c "MySQL Server" -u 27 mysql >/dev/null 2>&1 || :


vi /opt/after_install.sh
#!/bin/bash

mkdir -p /opt/swancmp/mysql/{log,run/mysqld,mysql,tmp} 					>/dev/null 2>&1 || :
/bin/touch /opt/swancmp/mysql/log/mysqld.log 						>/dev/null 2>&1 || :
/bin/chown mysql:mysql -R /opt/swancmp/mysql/log/mysqld.log 				>/dev/null 2>&1 || :
/bin/chown mysql:mysql -R /opt/swancmp/mysql/run/mysqld 				>/dev/null 2>&1 || :
/bin/chown mysql:mysql -R /opt/swancmp/mysql/tmp	 				>/dev/null 2>&1 || :
/bin/chown mysql:mysql -R /opt/swancmp/mysql/mysql 					>/dev/null 2>&1 || :

cp /opt/swancmp/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld >/dev/null 2>&1 || :
chkconfig mysqld on >/dev/null 2>&1 || :

# cp /opt/swancmp/mysql/support-files/my.cnf /etc/my.cnf

/opt/swancmp/mysql/bin/mysqld  --initialize --user=mysql --basedir=/opt/swancmp/mysql/ --datadir=/opt/swancmp/mysql/mysql >/dev/null 2>&1


vi /opt/before_remove.sh
#!/bin/bash

/etc/init.d/mysqld stop >/dev/null 2>&1 || :


vi /opt/after_remove.sh
#!/bin/bash

mv /opt/swancmp/mysql/mysql /opt/swancmp/mysql/mysql-$(date +%Y$m%d%H%M%S)
rm -rf /opt/swancmp/mysql/log
rm -rf /opt/swancmp/mysql/run
rm -rf /opt/swancmp/mysql/tmp


4. 打包
# mkdir -p /data/rpms/mysql-5.7.20
# cp -rf /data/download/mysql-5.7.20/opt /data/rpms/mysql-5.7.20

fpm -s dir -t rpm -p $(pwd) -n swancmp-mysql -v '5.7.20' \
	-C ${DIR_SRC_INSTALL} \
	--directories=${DIR_RPM_INSTALL}/bin \
	--directories=${DIR_RPM_INSTALL}/lib \
	--directories=${DIR_RPM_INSTALL}/docs \
	--directories=${DIR_RPM_INSTALL}/include \
	--directories=${DIR_RPM_INSTALL}/man \
	--directories=${DIR_RPM_INSTALL}/mysql-test \
	--directories=${DIR_RPM_INSTALL}/share \
	--directories=${DIR_RPM_INSTALL}/support-files \
	--directories=${DIR_RPM_INSTALL}/my.cnf \
	--directories=${DIR_RPM_INSTALL}/COPYING \
	--directories=${DIR_RPM_INSTALL}/COPYING-test \
	--directories=${DIR_RPM_INSTALL}/README \
	--directories=${DIR_RPM_INSTALL}/README-test \
	--config-files=${DIR_RPM_INSTALL}/my.cnf \
	--category=Applications/Databases \
	--url 'https://dev.mysql.com/doc/refman/5.7/en/' \
	--description 'mysql-5.7.20' \
	--vendor 'www.asiacom.net.cn' \
	--license 'GPL' \
	--iteration 1.el7 \
	--conflicts 'mariadb-libs' \
	--depends '/usr/bin/perl net-tools perl(Getopt::Long) perl(strict)' \
	--before-install /opt/before_install.sh \
	--after-install /opt/after_install.sh \
	--before-remove /opt/before_remove.sh \
	--after-remove /opt/after_remove.sh \
	-m "zhangliqiang@asiacom.net.cn" 


启动MySQL
[root@localhost ~]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!

查看日志
[root@localhost ~]# cat /opt/swancmp/mysql/log/mysqld.log 
2018-12-26T12:13:50.314830Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-26T12:13:50.877718Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-26T12:13:50.953826Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-26T12:13:51.019086Z 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: b48ed1b8-0907-11e9-8d25-080027f2328b.
2018-12-26T12:13:51.021745Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-26T12:13:51.023048Z 1 [Note] A temporary password is generated for root@localhost: wAB>te)Uc1Li
2018-12-26T12:14:15.403027Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-26T12:14:15.403113Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2018-12-26T12:14:15.403146Z 0 [Note] /opt/swancmp/mysql/bin/mysqld (mysqld 5.7.20) starting as process 21788 ...
2018-12-26T12:14:15.410581Z 0 [Note] InnoDB: PUNCH HOLE support available
2018-12-26T12:14:15.410631Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-12-26T12:14:15.410638Z 0 [Note] InnoDB: Uses event mutexes
2018-12-26T12:14:15.410642Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-12-26T12:14:15.410646Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-12-26T12:14:15.410650Z 0 [Note] InnoDB: Using Linux native AIO
2018-12-26T12:14:15.423683Z 0 [Note] InnoDB: Number of pools: 1
2018-12-26T12:14:15.423813Z 0 [Note] InnoDB: Using CPU crc32 instructions
2018-12-26T12:14:15.425086Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-12-26T12:14:15.431601Z 0 [Note] InnoDB: Completed initialization of buffer pool
2018-12-26T12:14:15.436539Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-12-26T12:14:15.445463Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2018-12-26T12:14:15.462798Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-12-26T12:14:15.462991Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-12-26T12:14:15.506295Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-12-26T12:14:15.508558Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2018-12-26T12:14:15.508591Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2018-12-26T12:14:15.509055Z 0 [Note] InnoDB: Waiting for purge to start
2018-12-26T12:14:15.559527Z 0 [Note] InnoDB: 5.7.20 started; log sequence number 2565377
2018-12-26T12:14:15.560300Z 0 [Note] Plugin 'FEDERATED' is disabled.
2018-12-26T12:14:15.566989Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2018-12-26T12:14:15.567015Z 0 [Note] Server hostname (bind-address): '*'; port: 3307
2018-12-26T12:14:15.567622Z 0 [Note] IPv6 is available.
2018-12-26T12:14:15.567640Z 0 [Note]   - '::' resolves to '::';
2018-12-26T12:14:15.567663Z 0 [Note] Server socket created on IP: '::'.
2018-12-26T12:14:15.568357Z 0 [Note] InnoDB: Loading buffer pool(s) from /opt/swancmp/mysql/mysql/ib_buffer_pool
2018-12-26T12:14:15.569776Z 0 [Note] InnoDB: Buffer pool(s) load completed at 181226 20:14:15
2018-12-26T12:14:15.587853Z 0 [Note] Event Scheduler: Loaded 0 events
2018-12-26T12:14:15.588146Z 0 [Note] /opt/swancmp/mysql/bin/mysqld: ready for connections.
Version: '5.7.20'  socket: '/tmp/mysql.sock'  port: 3307  Source distribution
2018-12-26T12:14:15.588163Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check. 
2018-12-26T12:14:15.588183Z 0 [Note] Beginning of list of non-natively partitioned tables
2018-12-26T12:14:15.598451Z 0 [Note] End of list of non-natively partitioned tables
[root@localhost ~]# cat /opt/swancmp/mysql/log/mysqld.log 
2018-12-26T12:13:50.314830Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-26T12:13:50.877718Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-12-26T12:13:50.953826Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-12-26T12:13:51.019086Z 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: b48ed1b8-0907-11e9-8d25-080027f2328b.
2018-12-26T12:13:51.021745Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-12-26T12:13:51.023048Z 1 [Note] A temporary password is generated for root@localhost: wAB>te)Uc1Li
2018-12-26T12:14:15.403027Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-12-26T12:14:15.403113Z 0 [Note] --secure-file-priv is set to NULL. Operations related to importing and exporting data are disabled
2018-12-26T12:14:15.403146Z 0 [Note] /opt/swancmp/mysql/bin/mysqld (mysqld 5.7.20) starting as process 21788 ...
2018-12-26T12:14:15.410581Z 0 [Note] InnoDB: PUNCH HOLE support available
2018-12-26T12:14:15.410631Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2018-12-26T12:14:15.410638Z 0 [Note] InnoDB: Uses event mutexes
2018-12-26T12:14:15.410642Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2018-12-26T12:14:15.410646Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
2018-12-26T12:14:15.410650Z 0 [Note] InnoDB: Using Linux native AIO
2018-12-26T12:14:15.423683Z 0 [Note] InnoDB: Number of pools: 1
2018-12-26T12:14:15.423813Z 0 [Note] InnoDB: Using CPU crc32 instructions
2018-12-26T12:14:15.425086Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2018-12-26T12:14:15.431601Z 0 [Note] InnoDB: Completed initialization of buffer pool
2018-12-26T12:14:15.436539Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2018-12-26T12:14:15.445463Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2018-12-26T12:14:15.462798Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2018-12-26T12:14:15.462991Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2018-12-26T12:14:15.506295Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2018-12-26T12:14:15.508558Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2018-12-26T12:14:15.508591Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2018-12-26T12:14:15.509055Z 0 [Note] InnoDB: Waiting for purge to start
2018-12-26T12:14:15.559527Z 0 [Note] InnoDB: 5.7.20 started; log sequence number 2565377
2018-12-26T12:14:15.560300Z 0 [Note] Plugin 'FEDERATED' is disabled.
2018-12-26T12:14:15.566989Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2018-12-26T12:14:15.567015Z 0 [Note] Server hostname (bind-address): '*'; port: 3307
2018-12-26T12:14:15.567622Z 0 [Note] IPv6 is available.
2018-12-26T12:14:15.567640Z 0 [Note]   - '::' resolves to '::';
2018-12-26T12:14:15.567663Z 0 [Note] Server socket created on IP: '::'.
2018-12-26T12:14:15.568357Z 0 [Note] InnoDB: Loading buffer pool(s) from /opt/swancmp/mysql/mysql/ib_buffer_pool
2018-12-26T12:14:15.569776Z 0 [Note] InnoDB: Buffer pool(s) load completed at 181226 20:14:15
2018-12-26T12:14:15.587853Z 0 [Note] Event Scheduler: Loaded 0 events
2018-12-26T12:14:15.588146Z 0 [Note] /opt/swancmp/mysql/bin/mysqld: ready for connections.
Version: '5.7.20'  socket: '/tmp/mysql.sock'  port: 3307  Source distribution
2018-12-26T12:14:15.588163Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check. 
2018-12-26T12:14:15.588183Z 0 [Note] Beginning of list of non-natively partitioned tables
2018-12-26T12:14:15.598451Z 0 [Note] End of list of non-natively partitioned tables



查找初始root密码
[root@localhost mysql]# grep -r 'temporary password' /opt/swancmp/mysql/log/mysqld.log 
2018-12-26T12:13:51.023048Z 1 [Note] A temporary password is generated for root@localhost: wAB>te)Uc1Li


登录
[root@localhost mysql]# /opt/swancmp/mysql/bin/mysql -uroot -p'wAB>te)Uc1Li'
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.20

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>

相关标签: mysql