MySQL5.7安装脚本
目录结构:
install_mysql.sh:安装脚本
my.cnf: MySQL配置文件
mysql-5.7.-linux-glibc2.-x86_64.tar.gz:MySQL二进制包
以下为目录中的文件:
#
## my.cnf for MySQL 5.7/8.0
## 注意:个别建议可能需要根据实际情况作调整,请自行判断或联系我,本人不对这些建议结果负相应责任
## 本配置文件主要适用于MySQL 5.7/.0版本
#
[client]
port =
socket = /var/run/mysql.sock [mysql]
prompt="\u@mysqldb \R:\m:\s [\d]> "
no-auto-rehash [mysqld]
user = mysql
port =
basedir = /usr/local/mysql
datadir = /usr/local/mysql/data
socket = /var/run/mysql.sock
pid-file = mysqldb.pid
character-set-server = utf8mb4
skip_name_resolve = #若你的MySQL数据库主要运行在境外,请务必根据实际情况调整本参数
default_time_zone = "+8:00" open_files_limit =
back_log =
max_connections =
max_connect_errors =
table_open_cache =
table_definition_cache =
table_open_cache_instances =
thread_stack = 512K
external-locking = FALSE
max_allowed_packet = 32M
sort_buffer_size = 4M
join_buffer_size = 4M
thread_cache_size =
interactive_timeout =
wait_timeout =
tmp_table_size = 32M
max_heap_table_size = 32M
slow_query_log =
log_timestamps = SYSTEM
slow_query_log_file = /usr/local/mysql/data/slow.log
log-error = /usr/local/mysql/data/error.log
long_query_time = 0.1
log_queries_not_using_indexes =
log_throttle_queries_not_using_indexes =
min_examined_row_limit =
log_slow_admin_statements =
log_slow_slave_statements =
server-id =
log-bin = /usr/local/mysql/data/mybinlog
sync_binlog =
binlog_cache_size = 4M
max_binlog_cache_size = 2G
max_binlog_size = 1G #注意:MySQL .0开始,binlog_expire_logs_seconds选项也存在的话,会忽略expire_logs_days选项
expire_logs_days = master_info_repository = TABLE
relay_log_info_repository = TABLE
gtid_mode = on
enforce_gtid_consistency =
log_slave_updates
slave-rows-search-algorithms = 'INDEX_SCAN,HASH_SCAN'
binlog_format = row
binlog_checksum =
relay_log_recovery =
relay-log-purge =
key_buffer_size = 32M
read_buffer_size = 8M
read_rnd_buffer_size = 4M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads =
lock_wait_timeout =
explicit_defaults_for_timestamp =
innodb_thread_concurrency =
innodb_sync_spin_loops =
innodb_spin_wait_delay = transaction_isolation = REPEATABLE-READ
#innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 5734M
innodb_buffer_pool_instances =
innodb_buffer_pool_load_at_startup =
innodb_buffer_pool_dump_at_shutdown =
innodb_data_file_path = ibdata1:1G:autoextend
innodb_flush_log_at_trx_commit =
innodb_log_buffer_size = 32M
innodb_log_file_size = 2G
innodb_log_files_in_group =
innodb_max_undo_log_size = 4G
innodb_undo_directory = /usr/local/mysql/data/undolog
innodb_undo_tablespaces = # 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 -
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 -
innodb_io_capacity =
innodb_io_capacity_max =
innodb_flush_sync =
innodb_flush_neighbors =
innodb_write_io_threads =
innodb_read_io_threads =
innodb_purge_threads =
innodb_page_cleaners =
innodb_open_files =
innodb_max_dirty_pages_pct =
innodb_flush_method = O_DIRECT
innodb_lru_scan_depth =
innodb_checksum_algorithm = crc32
innodb_lock_wait_timeout =
innodb_rollback_on_timeout =
innodb_print_all_deadlocks =
innodb_file_per_table =
innodb_online_alter_log_max_size = 4G
innodb_stats_on_metadata = #注意:MySQL 8.0.16开始删除该选项
internal_tmp_disk_storage_engine = InnoDB # some var for MySQL 5.7
innodb_checksums =
#innodb_file_format = Barracuda
#innodb_file_format_max = Barracuda
query_cache_size =
query_cache_type =
innodb_undo_logs = innodb_status_file =
#注意: 开启 innodb_status_output & innodb_status_output_locks 后, 可能会导致log-error文件增长较快
innodb_status_output =
innodb_status_output_locks = #performance_schema
performance_schema =
performance_schema_instrument = '%memory%=on'
performance_schema_instrument = '%lock%=on' #innodb monitor
innodb_monitor_enable="module_innodb"
innodb_monitor_enable="module_server"
innodb_monitor_enable="module_dml"
innodb_monitor_enable="module_ddl"
innodb_monitor_enable="module_trx"
innodb_monitor_enable="module_os"
innodb_monitor_enable="module_purge"
innodb_monitor_enable="module_log"
innodb_monitor_enable="module_lock"
innodb_monitor_enable="module_buffer"
innodb_monitor_enable="module_index"
innodb_monitor_enable="module_ibuf_system"
innodb_monitor_enable="module_buffer_page"
innodb_monitor_enable="module_adaptive_hash" [mysqldump]
quick
max_allowed_packet = 32M
my.cnf
#!/bin/bash #Date:--
#Description:deploy MySQL(5.7+) service
#MySQL下载地址:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/
#my.cnf生成地址:http://imysql.cn/my_cnf_generator
. /etc/init.d/functions function Check_Mysql_Service(){
#该函数功能为检查当前机器是否已经启动MySQL程序
echo -e "\033[44;30m开始检查本机是否存在MySQL程序 \033[0m"
mysql_pid=$(pidof mysqld)
mysql_port=$(lsof -i:)
if ([[ ${mysql_pid} != '' ]] || [[ ${mysql_port} != '' ]]);then
action "当前本机存在MySQL服务或3306端口被占用,请确认" /bin/false
exit
else
action "当前本机不存在MySQL服务,检查通过" /bin/true
fi
echo -e "\n"
} function Mysql_Num_Version_Check(){
#该函数功能为检查当前部署的版本是否小于 5.7 主要因为my.cnf文件5.7以下未验证
echo -e "\033[44;30m开始检查部署MySQL版本 \033[0m"
mysql_num=$(ls -l .|grep mysql-.*.tar.gz|wc -l)
if [[ ${mysql_num} != ]];then
action "当前目录下没有或存在多个MySQL安装文件,请确保只有一个!!" /bin/false
exit
fi
mysql_version=$(ls .|grep mysql-.*.tar.gz|awk -F- '{print $2}')
mysql_version_num=$(ls .|grep mysql-.*.tar.gz|awk -F- '{print $2}'|awk -F. '{print $2}')
if [[ ${mysql_version_num} -lt ]];then
action "MySQL部署版本不能低于5.7" /bin/false
exit
fi
while true;
do
read -p "当前部署的,MySQL版本为:${mysql_version},是否部署(y/n):" deploy_choose
if ([[ ${deploy_choose} == "y" ]] || [[ ${deploy_choose} == "Y" ]]);then
echo "开始部署"
echo -e "\n"
break
elif ([[ ${deploy_choose} == "n" ]] || [[ ${deploy_choose} == "N" ]]);then
echo "退出部署"
break
else
echo -e "\033[41;30m错误的选项,请确认后重新输入!\033[0m"
continue
fi
done
} function Decode_Mysql(){
#该函数功能为获取用户指定的MySQL basedir目录以及MySQL datadir目录
export script_path=$(pwd $)
tar_name=$(ls .|grep mysql-.*.tar.gz)
tar_dir=${tar_name%.tar.gz*}
read -p "开始解压二进制文件,请确认解压目录(默认路径 /usr/local/):" decode_dir
decode_dir=${decode_dir:-/usr/local}
if [[ -d ${decode_dir}/${tar_dir} ]];then
while true;
do
read -p "${decode_dir}/${tar_dir}目录已存在,是否覆盖(y/n)?" overwrite #检查解压目录下是否已经存在解压的文件
if ([[ ${overwrite} == "y" ]] || [[ ${overwrite} == "Y" ]]);then
echo -e "\n"
rm -rf ${decode_dir}/${tar_dir} && rm -f ${decode_dir}/mysql
break
elif ([[ ${overwrite} == "n" ]] || [[ ${overwrite} == "N" ]]);then
echo "退出部署"
exit
else
echo -e "\033[41;30m错误的选项,请确认后重新输入!\033[0m"
continue
fi
done
fi while true;
do
if [[ -d ${decode_dir} ]];then
export decode_dir=${decode_dir}
break
elif [[ ${decode_dir} == '' ]];then
export decode_dir=/usr/local
break
else
read -t -p "${decode_dir}目录不存在,请重新输入(默认路径 /usr/local/):" decode_dir
[[ $? -ne ]] && echo -e "\033[41;30m选择超时,使用默认路径 /usr/local/!\033[0m"
continue
fi
done
echo "正在解压至${decode_dir}目录,请稍后..."
tar xf ${tar_name} -C ${decode_dir} && cd ${decode_dir} && ln -s ${tar_dir} mysql
if [[ $? -eq ]];then
action "解压成功" /bin/true
echo -e "\n"
else
action "解压失败" /bin/false
fi
} function Mysql_User(){
echo -e "\033[44;30m检查MySQL用户\033[0m"
id mysql &> /dev/bull
if [[ $? -eq ]];
then
action "MySQL 用户已存在,无需创建" /bin/true
else
echo "MySQL 用户不存在,新建MySQL用户"
groupadd -g mysql && useradd -r -g -u -s /bin/false mysql && chown -R mysql.mysql ${decode_dir}/mysql
[[ $? -eq ]] && action "新建MySQL用户:mysql" /bin/true
fi
id mysql
echo -e "\n"
} function Create_AND_Modify_Config_File(){
[[ -f /etc/my.cnf ]] && mv /etc/my.cnf /etc/my.cnf-$(date +%F-%H:%H:%S)
cd ${script_path} && cp my.cnf /etc/
read -p "开始生成my.cnf文件,请选择MySQL数据目录(默认 ${decode_dir}/mysql/data 目录):" data_dir
while true;
do
if ([[ ${data_dir} != '' ]] && [[ $(ls -A ${data_dir}) != '' ]]);then #判断指定的数据目录是否存在数据
read -p "${data_dir}不为空,请重新选择(默认 ${decode_dir}/mysql/data 目录):" data_dir
continue
else
break
fi
done while true;
do
if [[ -d ${data_dir} ]];then
export data_dir=${data_dir}
break
elif [[ ${data_dir} == '' ]];then
export data_dir=${decode_dir}/mysql/data
break
else
read -p "${data_dir}目录不存在,请重新输入(默认路径 ${decode_dir}/mysql/data):" data_dir
[[ $? -ne ]] && echo "选择超时,使用默认路径"
continue
fi
done
echo -e "\033[44;30m 数据目录为:${data_dir}\033[0m"
system_mem_size=$(grep "^MemTotal" /proc/meminfo |awk '{print $2}') #获取当前系统内存大小,设置innodb 缓存大小
innodb_buffer_pool_size="$(echo ${system_mem_size}/1024/10*6|bc)M"
sed -i "s#^socket.*#socket = ${data_dir}/mysql.sock#g" /etc/my.cnf
sed -i "s#^slow_query_log_file.*#slow_query_log_file = ${data_dir}/slow.log#g" /etc/my.cnf
sed -i "s#^log-error.*#log-error = ${data_dir}/error.log#g" /etc/my.cnf
sed -i "s#^log-bin.*#log-bin = ${data_dir}/mybinlog#g" /etc/my.cnf
sed -i "s#^innodb_buffer_pool_size.*#innodb_buffer_pool_size = ${innodb_buffer_pool_size}M#g" /etc/my.cnf
sed -i "s#^innodb_undo_directory.*#innodb_undo_directory = ${data_dir}/undolog#g" /etc/my.cnf
sed -i "s#^basedir.*#basedir = ${decode_dir}/mysql#g" /etc/my.cnf
sed -i "s#^datadir.*#datadir = ${data_dir}#g" /etc/my.cnf
echo -e "\n"
} function Init_Mysql(){
echo -e "\033[44;30m开始初始化数据库\033[0m"
cd ${decode_dir}/mysql && bin/mysqld --initialize --user=mysql --basedir=${decode_dir}/mysql --datadir=${data_dir}
if [[ $? -eq ]];then
action "MySQL初始化完毕" /bin/true
mysql_init_pwd=$(grep "temporary password" ${data_dir}/error.log |awk -F "[: ]" '{print $NF}')
echo "MySQL初始化密码为:${mysql_init_pwd}"
chown -R mysql:mysql ${decode_dir}/mysql
echo -e "\n"
else
action "MySQL初始化失败请查看${data_dir}/error.log日志" /bin/false
exit
fi
} function Set_System_Server_And_Init(){
echo -e "\033[44;30m开始设置MySQL开机自启 firewalld 全局环境变量 启动脚本 \033[0m"
decode_dir=${decode_dir:-/usr/local}
cd ${decode_dir}/mysql/support-files && cp mysql.server /etc/init.d/mysqld
[[ $? -eq ]] && action "服务脚本拷贝成功" /bin/true || action "服务脚本拷贝失败" /bin/false
if ([[ ${decode_dir} != "/usr/local" ]] || [[ ${decode_dir} != "/usr/local/" ]]);then
sed -i "s#^basedir=.*#basedir=${decode_dir}/mysql#g" /etc/init.d/mysqld
fi
if ([[ ${data_dir} != "/usr/local/mysql/data" ]] || [[ ${data_dir} != "/usr/local/mysql/data/" ]]);then
sed -i "s#^datadir=.*#datadir=${data_dir}#g" /etc/init.d/mysqld
fi
echo "export PATH=${decode_dir}/mysql/bin:$PATH" >> ~/.bash_profile && source ~/.bash_profile
chkconfig --level mysqld on
[[ $? -eq ]] && action "设置开机自启成功" /bin/true || action "设置开机自启失败" /bin/false
firewall-cmd --zone=public --add-port=/tcp --permanent && systemctl restart firewalld.service
[[ $? -eq ]] && action "防火墙规则设置成功" /bin/true || action "防火墙规则设置失败,请检查firewalld服务!" /bin/false
echo -e "\n"
} function Start_Mysql(){
echo -e "\033[44;30m开始启动MySQL服务\033[0m"
/etc/init.d/mysqld start &> /dev/null
[[ $? -eq ]] && action "启动成功..." /bin/true || action "启动失败,请查看${data_dir}/error.log日志" /bin/false
echo -e "\n"
echo -e "\033[41;30m使用 ALTER USER 'root'@'localhost' IDENTIFIED BY 'YOURPASSWD' 命令设置MySQL root用户本地登录密码\033[0m"
echo -e "\033[41;30m使用 GRANT ALL PRIVILEGES ON . TO 'root'@'%' IDENTIFIED BY 'YOUR PASSWD' WITH GRANT OPTION; 命令设置MySQL root用户远程登录密码\033[0m"
echo -e "\033[41;30m密码强度要求包含 大小写字母、特殊字符、数字\033[0m"
} function Main(){
Check_Mysql_Service;
Mysql_Num_Version_Check;
Decode_Mysql;
Mysql_User;
Create_AND_Modify_Config_File;
Init_Mysql;
Set_System_Server_And_Init;
Start_Mysql;
}
Main;
install_mysql.sh
MySQL二进制文件下载地址:http://ftp.ntu.edu.tw/MySQL/Downloads/MySQL-5.7/
使用方法:
MySQL5.7安装脚本的更多相关文章
- mysql5.x安装脚本
直接贴出来: #!/bin/bash #linux安装mysql服务分两种安装方法: #①源码安装,优点是安装包比较小,只有十多M,缺点是安装依赖的库多,安装编译时间长,安装步骤复杂容易出错: #②使 ...
- 实战-Mysql5.6.36脚本编译安装及初始化
概述 本文为centos7.3自动化编译安装mysql5.3.6的脚本及后续初始化操作,话不多少,直接上脚本. 安装脚本install.py如下: #coding=utf-8 #!/usr/bin/p ...
- mysql5.7一键安装脚本
0. 概述 最近鼓捣出了一个mysql安装脚本,将该脚本,mysql的my.cnf文件,mysql的安装包这三个文件放在同一个目录下面,执行sh mysql-auto-install.sh就可以完成m ...
- mysql5.6安装
mysql5.6安装 #卸载原有的mysqlyum remove mysql*ls /etc/my.cnf*mv /etc/my.cnf* /tmp/ #安装依赖包yum install make c ...
- LAMP最新源码一键安装脚本
Linux+Apache+MySQL+PHP (脚本可以选择是否安装+Pureftpd+User manager for PureFTPd+phpMyAdmin+memcache),添加虚拟主机请执行 ...
- LNMP、LAMP、LANMP一键安装脚本(定期更新)[转]
这个脚本是使用shell编写,为了快速在生产环境上部署LNMP/LAMP/LANMP(Linux.Nginx/Tengine.MySQL/MariaDB/Percona.PHP),适用于CentOS/ ...
- 自动安装脚本-------------基于LVMP搭建Nagios 监控
Mysql初始化参数(mysql-5.6.31) /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local ...
- MySQL安装脚本0104-亲试ok
#!/bin/bash export host_ip=192.168.7.79 export password=123456 echo '#1.取master主机ip的后三位作为master的se ...
- Linux下安装mysql(示例mysql5.6安装)
1.首先检查你的linux上是否已经安装了mysql rpm -qa|grep mysql 2.如果mysql的版本不是想要的版本.需要把mysql卸载 yum remove mysql mysql- ...
随机推荐
- 你以为你真的了解final吗?
本人免费整理了Java高级资料,涵盖了Java.Redis.MongoDB.MySQL.Zookeeper.Spring Cloud.Dubbo高并发分布式等教程,一共30G,需要自己领取.传送门:h ...
- jdk api 1.6,1.7,1.8,1.9版本(中文)
有需要的朋友,请自行到百度云下载 链接:https://pan.baidu.com/s/18WgEZ1WpBz5YexbbgikJcA 提取码:xry4
- windows下dubbo-admin2.6.x之后版本的安装
安装zookeeper(单机) 下载bin.tar.gz的版本,解压 conf下的zoo_sample.cfg改zoo.cfg zoo.cfg里添加配置 dataDir=G:/zookeeper-/d ...
- 在执行方法和Web资源中获取传递过来参数的值
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复228或者20161026可方便获取本文,同时可以在第一间得到我发布的最新的博文信息,follow me!我的网站是 www.luoyong. ...
- 算法基础:BFS和DFS的直观解释
算法基础:BFS和DFS的直观解释 https://cuijiahua.com/blog/2018/01/alogrithm_10.html 一.前言 我们首次接触 BFS 和 DFS 时,应该是在数 ...
- Java 并发(1)——线程安全
我们对并发一词并不陌生,它通常指多个任务同时执行.实际上这不完全对,“并行”才是真正意义上的同时执行,而“并发”则更偏重于多个任务交替执行.有时候我们会看见一些人一边嘴里嚼着东西一边讲话,这是并行:当 ...
- Pycharm 2019 添加 docker 解释器
打开docker的tls
- 3.Python网络编程_多任务问题抛出
#单线程程序 import time def sing(): """唱歌5秒钟""" for i in range(5): print(&q ...
- 6. Vue - 声明周期
一.官方vue生命周期流程图 二.vue声明周期介绍 beforeCreate执行时:data和el均未初始化,值为undefined created执行时:Vue 实例观察的数据对象data已经配置 ...
- itestpdf
itestpdf jar pdf