博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
mysql 自动化 安装_Mysql自动化安装
阅读量:5010 次
发布时间:2019-06-12

本文共 6711 字,大约阅读时间需要 22 分钟。

#!/bin/sh

# 安装mysql5.7.21 X64 二进制安装

# create by uug 201808

#mysql基础路径设置

mysql_port=$1

mysql_port=${mysql_port:-3306}

echo ${mysql_port}

#mysql_port=3306

filename="Percona-Server-5.7.26-29-Linux.x86_64.ssl101.tar.gz"

mysql_buffer=$2

mysql_buffer=${mysql_buffer:-5G}

echo ${mysql_buffer}

mysql_dir="/usr/local/mysql"

mysql_cmd="/data/mysql_${mysql_port}"

mysql_datadir="${mysql_cmd}/mydata"

mysql_binlog="${mysql_cmd}/binlog"

mysql_log="${mysql_cmd}/innodb_log"

mysql_ts="${mysql_cmd}/innodb_ts"

mysql_tmp="${mysql_cmd}/tmpdir"

mysql_passwd="admin"

function removemysql()

{

yum -y remove mysql*

}

#init set up Library

function init()

{

#依赖库和开发工具

#操作系统基础包

yum -y install gcc gcc-c++ \

autoconf \

libjpeg \

libjpeg-devel \

libpng \

libpng-devel \

freetype \

freetype-devel \

libxml2 \

libxml2-devel \

zlib \

zlib-devel \

glibc \

glibc-devel \

glib2 \

glib2-devel \

bzip2 \

bzip2-devel \

ncurses \

ncurses-devel \

curl \

curl-devel \

e2fsprogs \

e2fsprogs-devel \

krb5 \

krb5-devel \

libidn \

libidn-devel \

openssl \

openssl-devel \

openldap \

openldap-devel \

nss_ldap \

openldap-clients \

openldap-servers

yum -y install gcc

make

yum -y install libaio-devel

yum -y groupinstall 开发工具

yum -y install ncurses*

#Php

yum -y install gd-devel libjpeg-devel libpng-devel

freetype-devel libxml2-devel curl-devel freetype-devel

#Mysql数据库专用包

yum -y install bison gcc gcc-c++ autoconf automake zlib*

libxml* ncurses-devel libtool-ltdl-devel* libnuma*

yum -y install yum-fastestmirror yum-presto

yum -y install gcc gcc-c++ \

autoconf libjpeg \

libjpeg-devel libpng \

libpng-devel freetype \

freetype-devel libxml2 \

libxml2-devel zlib \

zlib-devel glibc \

glibc-devel glib2 \

glib2-devel bzip2 \

bzip2-devel ncurses \

ncurses-devel curl \

curl-devel e2fsprogs \

e2fsprogs-devel \

krb5-devel libidn \

libidn-devel openssl \

openssl-devel nss_ldap \

openldap openldap-devel

\

openldap-clients \

openldap-servers \

libxslt-devel ntp \

libtool-ltdl bison \

libtool vim-enhanced

}

function install_mysql()

{

cd ~

useradd mysql

useradd -g mysql -M -s /sbin/nologin

mysql

#安装目录初始化

mkdir -p $mysql_datadir

mkdir -p $mysql_binlog

mkdir -p $mysql_log

mkdir -p $mysql_ts

mkdir -p $mysql_tmp

chmod 750 $mysql_datadir

chmod 750 $mysql_binlog

chmod 750 $mysql_log

chmod 750 $mysql_ts

chmod 750 $mysql_tmp

chown mysql.mysql -R $mysql_datadir

chown mysql.mysql -R $mysql_binlog

chown mysql.mysql -R $mysql_log

chown mysql.mysql -R $mysql_ts

chown mysql.mysql -R $mysql_tmp

cd /usr/local

tar xvfz

Percona-Server-5.7.26-29-Linux.x86_64.ssl101.tar.gz

ln -s

Percona-Server-5.7.26-29-Linux.x86_64.ssl101 mysql

touch $mysql_cmd/my${mysql_port}.cnf

cat > $mysql_cmd/my${mysql_port}.cnf << EOF

[mysqldump]

quick

max_allowed_packet = 50M

default-character-set=utf8mb4

[client]

default-character-set=utf8mb4

[mysql]

prompt="\\u@\\h:\\p : \\d \\r:\\m:\\s> "

#pager="less -i -n -S"

#tee=/home/mysql_3306/query.log

no-auto-rehash

default-character-set=utf8mb4

show-warnings

[mysqld]

user = mysql

basedir = ${mysql_dir}

interactive_timeout = 3600

wait_timeout = 3600

character-set-server = utf8mb4

open_files_limit = 65535

max_connections = 1000

max_connect_errors = 100000

thread_pool_max_threads=1000

lower_case_table_names=0

default-storage-engine = InnoDB

skip-name-resolve = 1

log_warnings = 2

slave-skip-errors = 1032,1075,1396

optimizer_switch='mrr_cost_based=off,batched_key_access=on'

#logs

slow_query_log = 1

long_query_time = 2

#gtid

gtid_mode=on

enforce-gtid-consistency=on

binlog-gtid-simple-recovery=1

log_slave_updates=1

#binlog

binlog_format = row

binlog_cache_size = 20M

max_binlog_size = 1G

max_binlog_cache_size = 2G

expire_logs_days = 5

#relay log

skip_slave_start = 0

max_relay_log_size = 1G

relay_log_purge = 1

relay_log_recovery = 1

slave_net_timeout=60

master_info_repository = "TABLE"

relay_log_info_repository = "TABLE"

#buffers & cache

table_open_cache = 2048

table_definition_cache = 2048

sort_buffer_size = 1M

join_buffer_size = 1M

thread_cache_size = 256

query_cache_size = 0

query_cache_type = 0

query_cache_limit = 256K

query_cache_min_res_unit = 512

thread_stack = 192K

max_heap_table_size = 1G

tmp_table_size = 500M

key_buffer_size = 1M

read_buffer_size = 1M

read_rnd_buffer_size = 1M

bulk_insert_buffer_size = 4M

max_allowed_packet = 50M

#myisam

myisam_sort_buffer_size = 128M

myisam_max_sort_file_size = 1G

myisam_repair_threads = 1

#undo

innodb_undo_log_truncate=1

innodb_undo_tablespaces=6

innodb_undo_logs=128

innodb_max_undo_log_size=2G

#innodb

innodb_buffer_pool_instances =1

innodb_data_file_path = ibdata:1G:autoextend

innodb_flush_log_at_trx_commit = 0

innodb_log_buffer_size = 64M

innodb_log_file_size = 2G

innodb_log_files_in_group = 2

innodb_max_dirty_pages_pct = 50

innodb_file_per_table = 1

innodb_lock_wait_timeout = 10

innodb_rollback_on_timeout

innodb_status_file = 1

innodb_io_capacity = 2000

innodb_flush_method = O_DIRECT

innodb_open_files = 65535

innodb_file_format=Barracuda

innodb_file_format_check=1

innodb_strict_mode=1

#ssd上面设置这个参数

innodb_flush_neighbors=0

innodb_thread_concurrency = 0

innodb_purge_threads = 1

sql_mode=NO_ENGINE_SUBSTITUTION

innodb_numa_interleave = 1

#每个实例的配置参数

port = ${mysql_port}

server-id = 1923306

pid-file=/tmp/mysql${mysql_port}.pid

socket = /tmp/mysql${mysql_port}.sock

log-error=${mysql_cmd}/error.log

log-bin = ${mysql_binlog}/mysql-bin

tmpdir = ${mysql_tmp}

datadir= ${mysql_datadir}

innodb_data_home_dir= ${mysql_ts}

innodb_log_group_home_dir=${mysql_log}

transaction_isolation=READ-COMMITTED

innodb_buffer_pool_size = ${mysql_buffer}

slow_query_log_file = ${mysql_cmd}/slow.log

innodb_undo_directory=${mysql_datadir}

EOF

chown mysql.mysql -R $mysql_cmd

#初始化数据库

$mysql_dir/bin/mysqld

--defaults-file=$mysql_cmd/my$mysql_port.cnf --initialize-insecure

--user=mysql

#启动数据库

$mysql_dir/bin/mysqld_safe

--defaults-file=$mysql_cmd/my$mysql_port.cnf &

sleep 10

#写入参数文件

echo 'export PATH=$PATH:'$mysql_dir'/bin' >>

/etc/profile

source /etc/profile

}

function checkmysql()

{

MYSQLPORT2=$( netstat -ant | grep ${mysql_port} | awk '{print

$4}')

echo ${MYSQLPORT2}

if [ ! -z ${MYSQLPORT2} ];then

echo -e

"\033[31m mysql5.7.21 X64 is sucess !!

\033[0m"

else

echo -e

"\033[31m mysql5.7.21 X64 is failure !!

\033[0m"

fi

}

#begin install

# check the Mysql

MYSQLPORT=$( netstat -ant | grep ${mysql_port} | awk '{print

$4}')

if [ ! -z $MYSQLPORT ];then

echo -e "\033[31m mysql5.7

X64 ${mysql_port} is exist,please change the port !! \033[0m"

else

removemysql

init

install_mysql

#checkmysql

fi

#注意初始化完修改密码,初始密码在日志文件中

#set password=password('XXX');

#update user set host='%';

#flush privileges;

#centos7 需要卸载默认的maridb数据库

#skip-grant-tables

#update user set authentication_string=PASSWORD('xxx') where

User='root';

#mysql -uroot -p -P13307 -h127.0.0.1

安装案例:sh mysqlInstall2.sh

3306 2G

转载地址:http://gaggp.baihongyu.com/

你可能感兴趣的文章
【网络流24题】No. 13 星际转移问题 (网络判定 最大流)
查看>>
解析$.grep()源码及透过$.grep()看(两次取反)!!的作用
查看>>
[模板] 字符串hash
查看>>
SGU438_The Glorious Karlutka River =)
查看>>
Linux集群及LVS简介
查看>>
简单几何(直线与圆的交点) ZOJ Collision 3728
查看>>
Codeforces Round #327 (Div. 2)
查看>>
如何解决Provisional headers are shown问题(转)
查看>>
开发网站遇到的bug
查看>>
实现简单的接口自动化测试平台
查看>>
EXCEL工作表合并
查看>>
Prime Path
查看>>
ODAC(V9.5.15) 学习笔记(三)TOraSession(2)
查看>>
单纯形法
查看>>
SQL中的replace函数
查看>>
java中的类型安全问题-Type safety: Unchecked cast from Object to ...
查看>>
如何解决最后一个尾注引用显示与致谢混为一谈的问题-下
查看>>
Java Socket编程 - 基于TCP方式的二进制文件传输【转】http://blog.csdn.net/jia20003/article/details/8248221...
查看>>
阅读之https及加密原理
查看>>
HDOJ4550 卡片游戏 随便销毁内存的代价就是wa//string类的一些用法
查看>>