CENTOS Mysql5.7数据库自动安装脚本
ztj100 2025-01-24 14:53 17 浏览 0 评论
对于多台服务器安装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
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
wait_timeout = 86400
lock_wait_timeout = 50
max_allowed_packet = 256M
max_connect_errors = 2000
max_connections = 2000
max_user_connections = 2000
join_buffer_size = 4M
sort_buffer_size = 4M
#table_definition_cache = 5000
#table_open_cache = 8000
#table_open_cache_instances = 4
#thread_cache_size = 9
#thread_stack = 256K
tmp_table_size = 32M
max_heap_table_size = 32M
binlog_cache_size = 1M
############# SAFETY ##############
#local_infile = OFF
#{$validate_password_enable}plugin-load = validate_password.so
#skip_name_resolve = ON
#sql_mode = STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION,ONLY_FULL_GROUP_BY
############# LOGGING #############
#general_log = 0
log_queries_not_using_indexes = OFF
log_throttle_queries_not_using_indexes = 0
log_slow_admin_statements = ON
log_error_verbosity = 3
long_query_time = 3
slow_query_log = ON
log_timestamps = SYSTE
############# REPLICATION #############
#binlog_checksum = CRC32
#master_verify_checksum = ON
#slave_sql_verify_checksum = ON
binlog_format = ROW
binlog_rows_query_log_events = ON
expire_logs_days = 3
max_binlog_size = 256M
enforce_gtid_consistency = ON
gtid_mode = ON
log_slave_updates = ON
master_info_repository = TABLE
relay_log_info_repository = TABLE
server_id=000001
#skip_slave_start = ON
#slave_net_timeout = 4
sync_binlog = 100
sync_master_info = 10000
sync_relay_log = 10000
sync_relay_log_info = 10000
slave_parallel_workers = 4
slave_parallel_type = LOGICAL_CLOCK
relay_log_recovery = ON
slave_skip_errors = all
[mysqld_safe]
log-error=/data/mysql/log/mysqld.log
pid-file=/data/mysql/var/mysqld.pid
[client]
#default-character-set=utf8
[mysql]
default-character-set=utf8
EOF
sed -i "s/server_id=000001/server_id=$server_id/g" /etc/my.cnf
cd /apps/mysql/bin
mysqld --initialize --user=mysql --basedir=/apps/mysql --datadir=/data/mysql/data
mysql_ssl_rsa_setup --datadir=/data/mysql/data
mysqld_safe > /dev/null 2>&1 &
sleep 15
ln -s /apps/mysql/bin/msql /usr/bin
passwd1=`cat /data/mysql/log/error.log | grep password | awk -F "root@localhost:" '{print $2}'| awk -F " " '{print $1}'`
echo "initial password:"$passwd1
passwd2="'test123'"
passwd3="test123"
echo "<---------------modify passwd------------------>"
mysql -uroot -h127.0.0.1 -p${passwd1} --connect-expired-password -e "alter user 'root'@'localhost' identified by ${passwd2}"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "grant all privileges on *.* to root@'%' identified by ${passwd2};"
echo "The root password has been changed:"$passwd3
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "grant replication slave,replication client on *.* to replic_user identified by 'test123';"
echo "The cluster user name have been created:replic_user"
echo "The cluster password have been created:test123"
mysql -uroot -h127.0.0.1 -p${passwd3} --connect-expired-password -e "FLUSH PRIVILEGES;"
echo "<---------------end------------------>"
备注
脚本内容可以根据自己的数据库版本进行调整,此脚本已在安装生产环境使用过,数据库的参数,可以根据自己的服务器配置进行调整。
相关推荐
- 电脑装系统用GHOST好,还是原装版本好?老司机都是这么装的
-
Hello大家好,我是兼容机之家的咖啡。安装Windows系统是原版ISO好还是ghost好呢?针对这个的问题,我们先来科普一下什么是ghost系统,和原版ISO镜像两者之间有哪些优缺点。如果是很了解...
- 苹果 iOS 14.5.1/iPadOS 14.5.1 正式版发布
-
IT之家5月4日消息今日凌晨,苹果发布了iOS14.5.1与iPadOS14.5.1正式版更新。这一更新距iOS14.5正式版发布过去了一周时间。IT之家了解到,苹果表示,...
- iOS 13.1.3 正式版发布 包含错误修复和改进
-
苹果今天发布了iOS13.1.3和iPadOS13.1.3,这是iOS13发布之后第四个升级补丁。iOS13.1.2两周前发布。iOS13.1.3主要包括针对iPad和...
- 还不理解 Error 和 Exception 吗,看这篇就够了
-
在Java中的基本理念是结构不佳的代码不能运行,发现错误的理想时期是在编译期间,因为你不用运行程序,只是凭借着对Java基本理念的理解就能发现问题。但是编译期并不能找出所有的问题,有一些N...
- Linux 开发人员发现了导致 MacBook“无法启动”的 macOS 错误
-
“多个严重”错误影响配备ProMotion显示屏的MacBookPro。...
- 启动系统时无法正常启动提示\windows\system32\winload.efi
-
启动系统时无法正常启动提示\windows\system32\winload.efi。该怎么解决? 最近有用户遇到了开机遇到的问题,是Windows未能启动。原因可能是最近更改了硬件或软件。虽然提...
- 离线部署之两种构建Ragflow镜像的方式,dify同理
-
在实际项目交付过程中,经常遇到要离线部署的问题,生产服务器无法连接外网,这时就需要先构建好ragflow镜像,然后再拷到U盘或刻盘,下面介绍两种构建ragflow镜像的方式。性能测试(网络情况好的情况...
- Go语言 error 类型详解(go语言 异常)
-
Go语言的error类型是用于处理程序运行中错误情况的核心机制。它通过显式的返回值(而非异常抛出)来管理错误,强调代码的可控性和清晰性。以下是详细说明及示例:一、error类型的基本概念内置接口...
- Mac上“闪烁的问号”错误提示如何修复?
-
现在Mac电脑的用户越来越多,Mac电脑在使用过程中也会出现系统故障。当苹果电脑无法找到系统软件时,Mac会给出一个“闪烁的问号”的标志。很多用户受到过闪烁问号这一常见的错误提示的影响,如何解决这个问...
- python散装笔记——177 sys 模块(python sys模块详解)
-
sys模块提供了访问程序运行时环境的函数和值,例如命令行参数...
- 30天自制操作系统:第一天(30天自制操作系统电子书)
-
因为咱们的目的是为了研究操作系统的组成,所以直接从系统启动的第二阶段的主引导记录开始。前提是将编译工具放在该文件目录的同级目录下,该工具为日本人川合秀实自制的编译程序,优化过的nasm编译工具。...
- 五大原因建议您现在不要升级iOS 13或iPadOS
-
今天苹果放出了iPadOS和iOS13的公测版本,任何对新版功能感兴趣的用户都可以下载安装参与测试。除非你想要率先体验Dark模式,以及使用AppleID来登陆Facebook等服务,那么外媒CN...
- Python安装包总报错?这篇解决指南让你告别pip烦恼!
-
在Python开发中,...
- 苹果提供了在M1 Mac上修复macOS重装错误的方案
-
#AppleM1芯片#在苹果新的M1Mac推出后不久,我们看到有报道称,在这些机器上恢复和重新安装macOS,可能会导致安装错误,使你的Mac无法使用。具体来说,错误信息如下:"An...
- 黑苹果卡代码篇三:常见卡代码问题,满满的干货
-
前言...
你 发表评论:
欢迎- 一周热门
- 最近发表
-
- 电脑装系统用GHOST好,还是原装版本好?老司机都是这么装的
- 苹果 iOS 14.5.1/iPadOS 14.5.1 正式版发布
- iOS 13.1.3 正式版发布 包含错误修复和改进
- 还不理解 Error 和 Exception 吗,看这篇就够了
- Linux 开发人员发现了导致 MacBook“无法启动”的 macOS 错误
- 启动系统时无法正常启动提示\windows\system32\winload.efi
- 离线部署之两种构建Ragflow镜像的方式,dify同理
- Go语言 error 类型详解(go语言 异常)
- Mac上“闪烁的问号”错误提示如何修复?
- python散装笔记——177 sys 模块(python sys模块详解)
- 标签列表
-
- idea eval reset (50)
- vue dispatch (70)
- update canceled (42)
- order by asc (53)
- spring gateway (67)
- 简单代码编程 贪吃蛇 (40)
- transforms.resize (33)
- redisson trylock (35)
- 卸载node (35)
- np.reshape (33)
- torch.arange (34)
- node卸载 (33)
- npm 源 (35)
- vue3 deep (35)
- win10 ssh (35)
- exceptionininitializererror (33)
- vue foreach (34)
- idea设置编码为utf8 (35)
- vue 数组添加元素 (34)
- std find (34)
- tablefield注解用途 (35)
- python str转json (34)
- java websocket客户端 (34)
- tensor.view (34)
- java jackson (34)