系统环境:
#cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
数据库版本:
mysql-boost-5.7.19.tar.gz
#注意是代boost版本
自动化安装脚本:
#!/bin/bash
##############################################################
# File Name: mysql_install.sh
# Version: V1.0
# Author: Tim
# Organization: opensource
# Created Time : 2017-08-30 18:23:47
# Description:
##############################################################
#定义文件路径
packageDir=/usr/local/src
versionDir=mysql-5.7.19
dataDir=/app/mysql
installDir=/app/local/mysql
#安装依赖软件
yum install -y gcc-c++ make cmake bison bison-devel ncurses-devel libaio-devel perl perl-Data-Dumper
#创建用户和用户组
cat /etc/passwd | grep mysql
if [ $? -ne 0 ];then
groupadd mysql
useradd -r -g mysql mysql
fi
创建安装目录
if [ ! -d $dataDir ];then
mkdir -p $dataDir/data
mkdir -p $dataDir/logs
mkdir -p $dataDir/temp
fi
if [ ! -d $installDir ];then
mkdir -p $installDir
fi
cd $packageDir
tar xvf mysql-boost-5.7.19.tar.gz
cd $versionDir
nowDir=pwd
if [ $nowDir == $packageDir/$versionDir ];then
cmake . -DCMAKE_INSTALL_PREFIX=/app/local/mysql
-DMYSQL_DATADIR=/app/mysql/data
-DMYSQL_UNIX_ADDR=/app/local/mysql/mysql.sock
-DWITH_BOOST=./boost/boost_1_59_0/
-DSYSCONFDIR=/app/local/mysql
-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
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8imb4
-DDEFAULT_COLLATION=utf8mb4_general_ci
-DWITH_EMBEDDED_SERVER=1
make && make install
make clean
fi
cp /app/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chown -Rf mysql:mysql /app/local/mysql/
chown -Rf mysql:mysql /app/mysql/
echo 'export PATH=$PATH:/app/local/mysql/bin:/app/local/mysql/lib' >> /etc/profile
source /etc/profile
cat > $installDir/my.cnf <
port = 3306
socket = /app/local/mysql/mysql.sock
[mysqld]
port = 3306
socket = /app/local/mysql/mysqld.sock
basedir = /app/local/mysql
datadir = /app/mysql/data
pid-file = /app/local/mysql/mysqld.pid
user = mysql
server-id = 1
init-connect = 'SET NAMES utf8mb4'
character-set-server = utf8mb4
skip-name-resolve
skip-networking
back_log = 300
max_connections = 1000
max_connect_errors = 6000
open_files_limit = 65535
table_open_cache = 128
max_allowed_packet = 4M
binlog_cache_size = 1M
max_heap_table_size = 8M
tmp_table_size = 16M
read_buffer_size = 2M
read_rnd_buffer_size = 8M
sort_buffer_size = 8M
join_buffer_size = 8M
key_buffer_size = 4M
thread_cache_size = 8
query_cache_type = 1
query_cache_size = 8M
query_cache_limit = 2M
ft_min_word_len = 4
log_bin = mysql-bin
binlog_format = mixed
expire_logs_days = 30
log_error = /app/mysql/logs/mysql-error.log
slow_query_log = 1
long_query_time = 1
slow_query_log_file = /app/mysql/logs/mysql-slow.log
performance_schema = 0
explicit_defaults_for_timestamp
skip-external-locking
default_storage_engine = InnoDB
#default-storage-engine = MyISAM
innodb_file_per_table = 1
innodb_open_files = 500
innodb_buffer_pool_size = 64M
innodb_write_io_threads = 4
innodb_read_io_threads = 4
innodb_thread_concurrency = 0
innodb_purge_threads = 1
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 2M
innodb_log_file_size = 32M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
bulk_insert_buffer_size = 8M
myisam_sort_buffer_size = 8M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
interactive_timeout = 28800
wait_timeout = 28800
[mysqldump]
quick
max_allowed_packet = 16M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
EOF
cd $installDir
chown -R mysql:mysql my.cnf
#mysqld --initialize-insecure --user=mysql --basedir=/app/local/mysql --datadir=/app/mysql/data --pid-file=/app/mysql/mysql.pid
$installDir/bin/mysqld --initialize-insecure --user=mysql --basedir=/app/local/mysql --datadir=/app/mysql/data
以上脚本安装完成:
#systemctl start mysqld
注意事项:
1.定义数据库安装目录,数据存放目录
- my.cnf文件要注意,建议用我提供的,后期再调优。如果不是我的my.cnf可以在执行$installDir/bin/mysqld 这条命令时可以创建库文件,但启动mysqld时日志提示pid文件不存在导致无法启动数据库。
- 可能报错
[root@localhost mysql]# systemctl start mysqld.service
Warning: mysqld.service changed on disk. Run 'systemctl daemon-reload' to reload units.
[root@localhost mysql]# systemctl daemon-reload
[root@localhost mysql]# systemctl restart mysqld
[root@localhost mysql]# ps -ef | grep mysqld
root 72650 1 1 02:19 ? 00:00:00 /bin/sh /app/local/mysql/bin/mysqld_safe --datadir=/app/mysql/data --pid-file=/app/local/mysql/mysqld.pid
mysql 74227 72650 3 02:19 ? 00:00:00 /app/local/mysql/bin/mysqld --basedir=/app/local/mysql --datadir=/app/mysql/data --plugin-dir=/app/local/mysql/lib/plugin --user=mysql --log-error=/app/mysql/logs/mysql-error.log --open-files-limit=65535 --pid-file=/app/local/mysql/mysqld.pid --socket=/app/local/mysql/mysqld.sock --port=3306
root 74259 31157 0 02:19 pts/3 00:00:00 grep --color=auto mysqld