对于多台服务器安装MySQL数据库,采用手工安装,是非常繁琐的,如果采取脚本批量安装,就非常的方便了,具体操作方法如下:
创建目录mkdir -p /Apps
mkdir -p /data
文章插图
上传安装包
文章插图
上传执行脚本
文章插图
授权脚本执行权限Chmod +x ./installMysql5.7.32
文章插图
执行脚本./installMysql5.7.32.sh
文章插图
文章插图
登录mysql数据库
文章插图
脚本信息
文章插图
脚本内容#!/bin/bash
port=`ss -tanl | grep 3306 |wc -l`
if [ $port -eq 1 ]; then
echo "3306 is exists please kill 3306!!"
exit
fi
if [ ! -d "/apps/" ];then
echo "The Directory:/apps/ no exist"
exit
fi
if [ ! -f "/apps/mysql-5.7.32-el7-x86_64.tar.gz" ];then
echo "The Directory:/apps/ No mysql-5.7.32-el7-x86_64.tar.gz please mysql-5.7.32-el7-x86_64.tar.gz to /apps/"
exit
fi
if [ ! -f "/apps/installMysql5.7.32.sh" ];then
echo "The Directory:/apps/ No installMysql5.7.32.sh please copy installMysql5.7.32.sh to /apps/"
exit
fi
if [ ! -d "/data/" ];then
echo "The Directory:/data/ no exist please mkdir /data"
exit
fi
echo "<---------------------begin--------------------->"
cd /apps/
tar -zxvf mysql-5.7.32-el7-x86_64.tar.gz
mv mysql-5.7.32-el7-x86_64 mysql
echo 'export PATH=/apps/mysql/bin:$PATH' >> /etc/profile
source /etc/profile
source /etc/profile
rm -rf /data/*
mkdir /data/mysql
mkdir /data/mysql/data
mkdir /data/mysql/tmp
mkdir /data/mysql/var
mkdir /data/mysql/log
touch /data/mysql/log/slow.log
touch /data/mysql/log/mysqld.log
i=`cat /etc/passwd | cut -f1 -d':' | grep -w mysql -c`
if [ $i -le 0 ]; then
groupadd mysql
useradd -r -s /sbin/nologin -g mysql mysql
fi
chown -R mysql:mysql /data/mysql
chown -R mysql:mysql /apps/mysql
chown mysql:mysql /apps/mysql
if [ -f "/etc/my.cnf" ];then
rm -f /etc/my.cnf
fi
server_id=`date +%Y%m%d%H%M%S`
cat > /etc/my.cnf << 'EOF'
[mysqld]
############# GENERAL #############
autocommit = ON
character_set_server = utf8
collation_server = utf8_general_ci
explicit_defaults_for_timestamp = ON
lower_case_table_names = 1
port = 3306
#read_only = ON
transaction_isolation = READ-COMMITTED
user =mysql
innodb_file_per_table = 1
#skip-grant-tables
############### PATH ##############
basedir = /apps/mysql
datadir = /data/mysql/data
tmpdir = /data/mysql/tmp
socket = /data/mysql/var/mysql.sock
pid_file = /data/mysql/var/mysql.pid
innodb_data_home_dir = /data/mysql/data
log_error = /data/mysql/log/error.log
general_log_file = /data/mysql/log/general.log
slow_query_log_file = /data/mysql/log/slow.log
#log_bin = /data/mysql/log/mysql-bin
#log_bin_index = /data/mysql/log/mysql-bin.index
relay_log = /data/mysql/log/relay-log
relay_log_index = /data/mysql/log/relay-log.index
############# INNODB #############
innodb_flush_method = O_DIRECT
【CENTOS Mysql5.7数据库自动安装脚本】innodb_buffer_pool_size = 30G
innodb_log_file_size = 1G
innodb_log_files_in_group = 4
innodb_flush_log_at_trx_commit = 2
innodb_support_xa = ON
innodb_strict_mode = ON
innodb_data_file_path = ibdata1:256M;ibdata2:256M:autoextend
innodb_temp_data_file_path = ibtmp1:512M:autoextend
innodb_lock_wait_timeout = 5
innodb_undo_tablespaces = 3
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 5120M
innodb_lock_wait_timeout = 50
innodb_read_io_threads = 16
innodb_write_io_threads = 16
innodb_io_capacity = 1200
innodb_io_capacity_max = 2400
innodb_lru_scan_depth = 512
####### CACHES AND LIMITS #########
interactive_timeout = 86400
推荐阅读
- go语言操作PostgreSQL数据库
- CENTOS自动巡检服务器性能指标
- Index MySQL查询合理使用索引:别让你的数据库负重前行
- 数据库:SQLServer分页查询整理
- 5大常用MySQL客户端工具,入门数据库必备收藏
- 面试被问:JDBC底层是如何连接数据库的?
- centos7 shell脚本一键安装nginx
- 生产环境下shell脚本:Mysql数据库备份和Mysql主从同步监控
- Mysql数据库实现主从同步,看这一篇就够了
- 如何在CentOS/RHEL系统中使用带VLAN标记的网卡