#!/bin/bash

MySQL_Package=Percona-Server-5.7.22-22-Linux.x86_64.ssl101.tar.gz
Package_Source=Percona-Server-5.7.22-22-Linux.x86_64.ssl101
PORT=3306 PrepareENV()
{
#Remove MySQL Local
yum -y remove mysql mysql-server
rm -rf /etc/my.cnf
userdel -r mysql
groupdel mysql echo '
mysql soft nproc 65536
mysql hard nproc 65536
mysql soft nofile 65536
mysql hard nofile 65536
' >> /etc/security/limits.conf groupadd mysql
useradd -g mysql -s /sbin/nologin -d /usr/local/mysql/ -MN mysql yum -y install gcc gcc-c++ make
yum -y install perl perl-devel
yum -y install ncurses ncurses-devel openssl-devel bison
} InstallMySQL()
{
tar zxvf ${MySQL_Package}
mv ${Package_Source} /usr/local/mysql if [ $? -eq 0 ];then
echo "Install MySQL successfully !"
chown -R mysql:mysql /usr/local/mysql
echo 'export PATH=/usr/local/mysql/bin:$PATH' >>/root/.bash_profile
else
echo "Install MySQL error ,exit !"
exit
fi
} InitMySQL()
{
mkdir -p /app/mysqldata/{$PORT/{data,tmp,binlog,redolog,undolog},backup,scripts}
# Init config file echo -e '
[client]
user=dba_user
password=msds007 [mysql]
no-auto-rehash
prompt = (\u@\h) [\d]>\_
default-character-set = utf8mb4 [mysqld]
########basic settings########
server-id = 1013306
port = 3306
user = mysql
bind_address = 192.168.1.101
autocommit = 1
character_set_server=utf8mb4
skip_name_resolve = 1
max_connections = 800
max_connect_errors = 1000
datadir = /app/mysqldata/3306/data
socket = /app/mysqldata/3306/mysql.sock
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
join_buffer_size = 134217728
tmp_table_size = 67108864
tmpdir = /app/mysqldata/3306/tmp
max_allowed_packet = 16777216
sql_mode = "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION,NO_ZERO_DATE,NO_ZERO_IN_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER"
interactive_timeout = 1800
wait_timeout = 1800
read_buffer_size = 16777216
read_rnd_buffer_size = 33554432
sort_buffer_size = 33554432
########log settings########
log_error = /app/mysqldata/3306/error.log
slow_query_log = 1
slow_query_log_file = /app/mysqldata/3306/slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 7
long_query_time = 1
min_examined_row_limit = 100
########replication settings########
master_info_repository = TABLE
relay_log_info_repository = TABLE
log_bin = /app/mysqldata/3306/binlog/mysql-bin.log
sync_binlog = 1
gtid_mode = on
enforce_gtid_consistency = 1
log_slave_updates
binlog_format = row
relay_log = /app/mysqldata/3306/binlog/relay-bin.log
relay_log_recovery = 1
binlog_gtid_simple_recovery = 1
slave_skip_errors = ddl_exist_errors
########innodb settings########
innodb_page_size = 8192
innodb_buffer_pool_size = 1G #生产环境做调整
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 2000
innodb_lock_wait_timeout = 5
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_log_group_home_dir = /app/mysqldata/3306/redolog/
innodb_undo_directory = /app/mysqldata/3306/undolog/
innodb_undo_logs = 128
innodb_undo_tablespaces = 3
innodb_flush_neighbors = 1
innodb_log_file_size = 128M #生产环境做调整
innodb_log_buffer_size = 16777216
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 0
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
########semi sync replication settings########
plugin_dir=/usr/local/mysql/lib/plugin
plugin_load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000 [mysqld-5.7]
innodb_buffer_pool_dump_pct = 40
innodb_page_cleaners = 4
innodb_undo_log_truncate = 1
innodb_max_undo_log_size = 2G
innodb_purge_rseg_truncate_frequency = 128
binlog_gtid_simple_recovery=1
log_timestamps=system
transaction_write_set_extraction=MURMUR32
show_compatibility_56=on
#binlog_checksum=NONE # only for group replication
#group replication setting #plugin_load=group_replication.so
#loose_group_replication_group_name=e5720089-6b00-11e5-b248-fa163e30f9a2 #loose_group_replication_start_on_boot=1
#loose_group_replication_recovery_user=rpl_user
#loose_group_replication_recovery_password=rpl_pass
'> /app/mysqldata/$PORT/my.cnf #set ENV
echo -e '
#set env
MYSQL_USER=dba_user
MYSQL_PASS=msds007
#check_parameter
if [ $# -ne 1 ]
then
HOST_PORT=3306
else
HOST_PORT=$1
fi
' >/app/mysqldata/scripts/mysql_env.ini
chmod 600 /app/mysqldata/scripts/mysql_env.ini ####################################################
#Make scirpt for use
echo -e '
#!/bin/sh
source /app/mysqldata/scripts/mysql_env.ini
echo "Startup MySQL Service: localhost_"${HOST_PORT}
/usr/local/mysql/bin/mysqld_safe --defaults-file=/app/mysqldata/${HOST_PORT}/my.cnf &
' >/app/mysqldata/scripts/mysql_db_startup.sh echo '
#!/bin/sh
source /app/mysqldata/scripts/mysql_env.ini
echo "Shutdown MySQL Service: localhost_"${HOST_PORT}
/usr/local/mysql/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PASS} -S /app/mysqldata/${HOST_PORT}/mysql.sock shutdown
' > /app/mysqldata/scripts/mysql_db_shutdown.sh echo -e '
#!/bin/sh
source /app/mysqldata/scripts/mysql_env.ini
echo "Login MySQL Service: localhost_"${HOST_PORT}
/usr/local/mysql/bin/mysql -u${MYSQL_USER} -p${MYSQL_PASS} -S /app/mysqldata/${HOST_PORT}/mysql.sock $2
' > /app/mysqldata/scripts/mysqlplus.sh chmod 755 /app/mysqldata/scripts/{mysql_db*,mysqlplus.sh}
echo 'export PATH=/app/mysqldata/scripts:$PATH' >>/root/.bash_profile ####################################################
chown -R mysql:mysql /app/mysqldata
/usr/local/mysql/bin/mysqld --defaults-file=/app/mysqldata/$PORT/my.cnf --initialize --user=mysql
/usr/local/mysql/bin/mysql_ssl_rsa_setup --defaults-file=/app/mysqldata/$PORT/my.cnf ####################################################
echo "start mysqld at boot time"
#ln -s /app/mysqldata/$PORT/my.cnf /etc/my.cnf
#cp -rf /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
#chkconfig --add mysql
#chkconfig mysql on
#service mysql stop
#service mysql start
#ln -s /app/mysqldata/$PORT/mysql.sock /tmp/mysql.sock
/app/mysqldata/scripts/mysql_db_startup.sh 3306 > /app/mysqldata/3306/mysql_db_startup.log 2>&1
chmod +x /etc/rc.d/rc.local
echo '/app/mysqldata/scripts/mysql_db_startup.sh 3306 > /app/mysqldata/3306/mysql_db_startup.log 2>&1' >> /etc/rc.local
sleep 5 echo "update root password"
tmppasswd=`grep password /app/mysqldata/$PORT/error.log | awk '{print $NF}'`
/usr/local/mysql/bin/mysql -uroot -p$tmppasswd -S /app/mysqldata/$PORT/mysql.sock --connect-expired-password -e "set password=password('msds007')"
/usr/local/mysql/bin/mysql -uroot -pmsds007 -S /app/mysqldata/$PORT/mysql.sock -e "grant all on *.* to dba_user@'%' identified by 'msds007'"
/usr/local/mysql/bin/mysql -uroot -pmsds007 -S /app/mysqldata/$PORT/mysql.sock -e "flush privileges"
/usr/local/mysql/bin/mysql -uroot -pmsds007 -S /app/mysqldata/$PORT/mysql.sock -e "select user,host,authentication_string from mysql.user" } PrepareENV
InstallMySQL
InitMySQL

用shell脚本安装MySQL-5.7.22-Percona版本的更多相关文章

  1. shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查)

    shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查) Shell脚本与MySQL数据库交互(增删改查) # 环境准备:安装mariadb 数据库 [ro ...

  2. centos 7.0 编译 安装mysql 5.6.22 过程 已完成~ 成功~ 撒花~

    mysql 下载目录/usr/local/srcmysql 解压目录 /usr/local/bin/mysql GitHub https://github.com/mysql/mysql-server ...

  3. shell脚本操作mysql数据库

    shell脚本操作mysql数据库,使用mysql的-e参数可以执行各种sql的(创建,删除,增,删,改.查)等各种操作 mysql  -hhostname -Pport -uusername -pp ...

  4. shell脚本操作mysql库

    shell脚本操作mysql数据库-e参数执行各种sql(指定到处编码--default-character-set=utf8 -s,去掉第一行的字段名称信息-N) 2011-05-11 18:18: ...

  5. shell脚本修复MySQL主从同步

    发布:thebaby   来源:net     [大 中 小] 分享一例shell脚本,用于修改mysql的主从同步问题,有需要的朋友参考下吧. 一个可以修改mysql主从同步的shell脚本. 例子 ...

  6. shell脚本获取mysql插入数据自增长id的值

    shell脚本获取mysql插入数据自增长id的值 在shell脚本中我们可以通过last_insert_id()获取id值,但是,需要注意的是,该函数必须在执行插入操作的sql语句之后,立即调用,否 ...

  7. CentOS 7.2使用源码包编译安装MySQL 5.7.22及一些操作

    CentOS 7.2使用源码包编译安装MySQL 5.7.22及一些操作 2018年07月05日 00:28:38 String峰峰 阅读数:2614   使用yum安装的MySQL一般版本比较旧,但 ...

  8. 如何在RedHat 7.0系统中安装mysql 5.7.22

    如何在RedHat 7.0系统中安装mysql 5.7.22 今天给大家介绍一下如何安装mysql5.7,在安装之前,首先要查看的是,你的系统中有没有已经安装过的情况.键入rpm -qa|grep m ...

  9. shell脚本安装python、pip--这种写法是错误的---每一个命令执行完都要判断是否执行成功,否则无法进行下一步

    shell脚本安装python.pip--不需要选择安装项目--不管用总报错,必须带上判断符号,while没有这种用法,写在这里为了以后少走弯路,所以不要用下面的执行了 首先把pip-.tgz 安装包 ...

  10. Ubuntu18 安装 MySQL 8.0.22

    Ubuntu18 安装 MySQL 8.0.22 网上教程都比旧,也不是第一次安装了,但依然还是花了比较多的时间,特此记录本次安装过程.因是安装完毕后回忆记录,或有错漏. 第一步: 下载 mysql ...

随机推荐

  1. slax中改变终端字体

    修改~/.Xresources文件 ! English font      Xterm*faceName: DejaVu Sans Mono=True:size=16 修改颜色: ! colos XT ...

  2. [BJOI2019]奥术神杖——AC自动机+DP+分数规划+二分答案

    题目链接: [BJOI2019]奥术神杖 答案是$ans=\sqrt[c]{\prod_{i=1}^{c}v_{i}}=(\prod_{i=1}^{c}v_{i})^{\frac{1}{c}}$. 这 ...

  3. IdentityServer4入门二

    在 IdentityServer4入门一 我们准备好了一个认证的服务端,这里做一个需要保护的API服务 首先,向解决方案新增一个项目.我们同样使用入门一的方式新增一个asp.net core Web程 ...

  4. expdp / impdp 用法详解 ,和exp / imp 的区别

    一  关于expdp和impdp     使用EXPDP和IMPDP时应该注意的事项:EXP和IMP是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用.EXPDP和IMPDP是服务端的工具程 ...

  5. 利用csv文件批量编辑更新sql

    历史表(popularity_ranking)数据中只存了用户手机号,业务需求中需要新增用户昵称字段, 这里我们用户表和popularity_ranking表在不同数据库中,有两种方法:1.编写后台服 ...

  6. layer快速点击会触发多次回调

    场景还原 测试同学反馈点击了一次操作,为什么会有两条操作记录? 我:???? 排查思路 查看日志,看一下是不是发了两次请求,果不其然啊: 并发了,同一时间发送了两次请求,出现了脏写. 原因 系统的co ...

  7. C之静态内存和动态内存

    静态内存: * 自动申请,自动释放* 大小固定,内存空间连续* 从栈上分配的内存叫静态内存 动态内存: * 程序员自己申请 * new/malloc* 大小取决于虚拟内存的大小,内存空间不连续* ja ...

  8. Eclipse的下载地址

    下载地址:http://eclipse.org/

  9. 阶段5 3.微服务项目【学成在线】_day04 页面静态化_10-freemarker静态化测试-基于模板文件静态化

    把resource拷贝到test目录下 只保留文件夹结构和test1.ftl这个模板文件就可以了. 新建一个包 编写测试类 使用freemaker提供的方法生成静态文件 Configuration是i ...

  10. Spring Aop(一)——Aop简介

    转发地址:https://www.iteye.com/blog/elim-2394629 1 Aop简介 AOP的全称是Aspect Oriented Programming,翻译成中文是面向切面编程 ...