用shell脚本安装MySQL-5.7.22-Percona版本
#!/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版本的更多相关文章
- shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查)
shell编程系列22--shell操作数据库实战之shell脚本与MySQL数据库交互(增删改查) Shell脚本与MySQL数据库交互(增删改查) # 环境准备:安装mariadb 数据库 [ro ...
- centos 7.0 编译 安装mysql 5.6.22 过程 已完成~ 成功~ 撒花~
mysql 下载目录/usr/local/srcmysql 解压目录 /usr/local/bin/mysql GitHub https://github.com/mysql/mysql-server ...
- shell脚本操作mysql数据库
shell脚本操作mysql数据库,使用mysql的-e参数可以执行各种sql的(创建,删除,增,删,改.查)等各种操作 mysql -hhostname -Pport -uusername -pp ...
- shell脚本操作mysql库
shell脚本操作mysql数据库-e参数执行各种sql(指定到处编码--default-character-set=utf8 -s,去掉第一行的字段名称信息-N) 2011-05-11 18:18: ...
- shell脚本修复MySQL主从同步
发布:thebaby 来源:net [大 中 小] 分享一例shell脚本,用于修改mysql的主从同步问题,有需要的朋友参考下吧. 一个可以修改mysql主从同步的shell脚本. 例子 ...
- shell脚本获取mysql插入数据自增长id的值
shell脚本获取mysql插入数据自增长id的值 在shell脚本中我们可以通过last_insert_id()获取id值,但是,需要注意的是,该函数必须在执行插入操作的sql语句之后,立即调用,否 ...
- CentOS 7.2使用源码包编译安装MySQL 5.7.22及一些操作
CentOS 7.2使用源码包编译安装MySQL 5.7.22及一些操作 2018年07月05日 00:28:38 String峰峰 阅读数:2614 使用yum安装的MySQL一般版本比较旧,但 ...
- 如何在RedHat 7.0系统中安装mysql 5.7.22
如何在RedHat 7.0系统中安装mysql 5.7.22 今天给大家介绍一下如何安装mysql5.7,在安装之前,首先要查看的是,你的系统中有没有已经安装过的情况.键入rpm -qa|grep m ...
- shell脚本安装python、pip--这种写法是错误的---每一个命令执行完都要判断是否执行成功,否则无法进行下一步
shell脚本安装python.pip--不需要选择安装项目--不管用总报错,必须带上判断符号,while没有这种用法,写在这里为了以后少走弯路,所以不要用下面的执行了 首先把pip-.tgz 安装包 ...
- Ubuntu18 安装 MySQL 8.0.22
Ubuntu18 安装 MySQL 8.0.22 网上教程都比旧,也不是第一次安装了,但依然还是花了比较多的时间,特此记录本次安装过程.因是安装完毕后回忆记录,或有错漏. 第一步: 下载 mysql ...
随机推荐
- zabbix监控项整理Items-key
agent.hostname:hostname,字符串 agent.ping:可用性检查,可用返回1:不可用返回空 agent.version:agent程序的版本,返回字符串 kernel.maxf ...
- java课后实验性问题7
1.异常处理 import javax.swing.*; class AboutException { public static void main(String[] a) { int i = 1, ...
- VMware下的CentOS7在桥接模式下,设置静态ip联网
之前在虚拟机下联网都用的是NAT模式,但现在做一个项目需要实现在两台笔记本电脑中的VMware虚拟机中的CentOS联网, 从网上查资料显示比较常规的方式是桥接模式.第一次用桥接模式联网,在网上查了很 ...
- CentOS7 docker开启tcp端口并进行客户端远程连接
#docker版本:18.09.0,最好保证客户端端口和服务端端口相同 [root@Centos7 ~]# dockerd-ce -v Docker version , build 4d60db4 网 ...
- Mysql mysqldumpslow命令详解
mysqldumpslow命令 /path/mysqldumpslow -s c -t 10 /database/mysql/slow-log 这会输出记录次数最多的10条SQL语句. 其中: -s, ...
- Java同步数据结构之SynchronousQueue
前言 严格来说SynchronousQueue并不是像它的名字那样是一种Queue,它更像是一个数据接力的交汇点,还记得在介绍Exchanger的时候提到过Exchanger可以看作是Synchron ...
- kotlin之操作符重载
一元操作符 表达式 对应的函数 +a a.unaryPlus() -a a.unaryMinus() !a a.not() a++ a.inc() a-- a.dec() fun main(arg: ...
- Build Telemetry for Distributed Services之Jaeger
github链接:https://github.com/jaegertracing/jaeger 官网:https://www.jaegertracing.io/ Jaeger: open sourc ...
- PAT 甲级 1026 Table Tennis (30 分)(坑点很多,逻辑较复杂,做了1天)
1026 Table Tennis (30 分) A table tennis club has N tables available to the public. The tables are ...
- 用Keras搭建神经网络 简单模版(四)—— RNN Classifier 循环神经网络(手写数字图片识别)
# -*- coding: utf-8 -*- import numpy as np np.random.seed(1337) from keras.datasets import mnist fro ...