#!/bin/bash
NETWORK=`hostname -i|awk -F'.' '{print $3}'`
BASEDIR=/data/xjk/software
MYSQLFILE=mysql-5.6.22-linux-glibc2.5-x86_64
DATADIR=/data/mysql
if [ ! -d $BASEDIR ]
then
/bin/mkdir -p $BASEDIR
fi
if [ ! -f $BASEDIR/$MYSQLFILE.tar.gz ]
then
cd $BASEDIR
wget http://192.18.$NETWORK.7/software/$MYSQLFILE.tar.gz
fi
apt-get install libaio1 autoconf perl perl-devel -y --force-yes
groupadd -g 68 mysql && useradd -d /data/mysql -s /sbin/nologin -c "MySQL Server" -u 68 -g 68 mysql
cd /usr/local
tar zxvf $BASEDIR/$MYSQLFILE.tar.gz
mv $MYSQLFILE mysql
cd mysql
chown -R mysql.mysql .
mkdir -p $DATADIR
chown -R mysql.mysql $DATADIR
scripts/mysql_install_db --user=mysql --datadir=/data/mysql
chown -R root .
cp support-files/mysql.server /etc/init.d/mysqld
sed -i '47s/datadir=/datadir=\/data\/mysql/g' /etc/init.d/mysqld
wget http://172.24.$NETWORK.7/software/conf/mysql/my.cnf -O /etc/my.cnf
ln -snf /usr/local/mysql/bin/mysql /usr/bin/mysql
mkdir /data/mysql/tmp && chown -R mysql.mysql /data/mysql/tmp
update-rc.d mysqld defaults
CENTOS 版 5.7
#!/bin/bash
==========================================================================
mysql-deploy.sh
to set up base line in CentOS 7
==========================================================================
MDIR=/var/www/my3306
if [ ! -d ${MDIR} ]
then
wget http://10.172.172.18:8899/download/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
tar -xf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
if [ $? != 0 ];then echo “ERROR”;exit 99;fi
yum install -y libaio
mkdir -p ${MDIR}/data /var/www/my3306/run ${MDIR}/tmp ${MDIR}/log/binlog ${MDIR}/log/iblog
useradd -r mysql -s /bin/false
mv mysql-5.7.31-linux-glibc2.12-x86_64 /usr/local/mysql
cp -a /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chown mysql:mysql -R /usr/local/mysql
chown mysql:mysql -R
M
D
I
R
e
c
h
o
′
e
x
p
o
r
t
P
A
T
H
=
/
u
s
r
/
l
o
c
a
l
/
m
y
s
q
l
/
b
i
n
:
{MDIR} echo 'export PATH=/usr/local/mysql/bin:
MDIRecho′exportPATH=/usr/local/mysql/bin:PATH’ >>/etc/profile
source /etc/profile
cat >/etc/my.cnf<<EOF
[mysql]
CLIENT
port = 3306
socket = /var/www/my3306/run/mysql.sock
[mysqld]
GENERAL
port = 3306
datadir=/var/www/my3306/data
socket=/var/www/my3306/run/mysql.sock
tmpdir=/var/www/my3306/tmp
##GTID##
gtid_mode = ON
enforce_gtid_consistency = ON
##SLAVE PARALLEL##
slave_parallel_type = LOGICAL_CLOCK
slave_parallel_workers = 2
LOG
log-queries-not-using-indexes
log-slow-admin-statements
slow-query-log = 1
long_query_time = 3
binlog_format = row
log_bin=/var/www/my3306/log/binlog/binlog
expire_logs_days = 7
relay_log_recovery = 1
log_error=/var/www/my3306/log/error.log
slow_query_log_file=/var/www/my3306/log/slow.log
relay_log=/var/www/my3306/log/relaylog
relay_log_index=/var/www/my3306/log/relay.index
relay_log_info_file=/var/www/my3306/log/relay-log.info
CACHE AND LIMIT##
tmp_table_size = 256M
max_heap_table_size = 256M
read_buffer_size = 512K
sort_buffer_size = 512K
max_connections = 1000
max_connect_errors = 100000
open-files-limit = 65535
table_open_cache = 10240
query-cache-type = 0
query-cache-size = 0
INNODB
innodb_data_home_dir=/var/www/my3306/log/iblog
innodb_log_group_home_dir=/var/www/my3306/log/iblog
innodb-log-files-in-group = 2
innodb-file-per-table = 1
innodb-log-file-size = 512M
innodb_buffer_pool_size = 1G
innodb_log_buffer_size = 16M
innodb_flush_log_at_trx_commit = 1
innodb_lock_wait_timeout = 50
innodb_flush_method = O_DIRECT
sql_mode = ‘’
sync_binlog = 1
MYISAM
key_buffer_size = 50M
SAFETY
skip-name-resolve
skip-symbolic-links
skip-external-locking
max_allowed_packet = 16M
wait_timeout = 3600
interactive_timeout = 3600
binlog_cache_size = 4M
CHATSET
character_set_server = utf8mb4
#default_character_set = utf8
server-id = 20
log_slave_updates = 1
skip-slave-start = 1
MySQL5.7
explicit-defaults-for-timestamp
log_timestamps = SYSTEM
master_info_repository = TABLE
relay_log_info_repository = TABLE
innodb_undo_tablespaces=3 #设置为3个
innodb_undo_logs=128 #默认128个
innodb_undo_directory =/var/www/my3306/log/undolog
#[client]
#socket=/var/www/my3306/run/mysql.sock
EOF
/usr/local/mysql/bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/var/www/my3306/data
/etc/init.d/mysqld start
rm -f ./mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
rm -f ./mysql-deploy.sh
else
echo “mysql已存在”
exit 99
fi