#!/bin/sh
mysql_install_dir=/usr/local/mysql
mysql_data_dir=/usr/local/mysql/data
mysql_6_version=5.6.17
MYSQL_VERSION=5.6.17
CMAKE_VERSION=2.8.12.2
dbrootpwd=root

[ -f /etc/init.d/functions ] && . /etc/init.d/functions
echo
echo "-----------step 1:add mysql user----"
useradd -s /sbin/nologin -M mysql
sleep 1

MYSQL(){
rpm -Uvh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum -y install make gcc gcc-c++  ncurses-devel gcc-g77 flex bison file libtool libtool-libs autoconf kernel-devel libjpeg libjpeg-devel libpng libpng-devel libpng10 libpng10-devel gd gd-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-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 gettext gettext-devel ncurses-devel gmp-devel pspell-devel unzip libcap lsof

[ ! -f cmake-${CMAKE_VERSION}.tar.gz  ] && \
wget http://www.o2oxy.cn/wp-content/uploads/2017/05/cmake-2.8.12.2.tar.gz
echo "-------- stop 2: download mysql "
[ ! -f mysql-${MYSQL_VERSION}.tar.gz ] && \
http://www.o2oxy.cn/wp-content/uploads/2017/05/mysql-5.6.17.tar.gz
tar zxvf cmake-2.8.12.2.tar.gz && cd cmake-2.8.12.2 && ./configure && make && make install && cd ..
mkdir -p $mysql_data_dir 
chown -R mysql:mysql $mysql_install_dir
tar zxf mysql-${MYSQL_VERSION}.tar.gz
cd mysql-${MYSQL_VERSION} && /usr/local/bin/cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/var/lib/mysql/mysql.sock -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_USER=mysql -DWITH_DEBUG=0 -DWITH_SSL=system && make && make install

if [ -d support-files/ ];then
   action "YES" /bin/true
   cd support-files/
   if [ -f /etc/my.cnf ];then
   mv /etc/my.cnf /etc/my.cnf.bak
   cat >>/etc/my.cnf<<EOF
[client]
port = 3306
socket =$mysql_install_dir/mysql.sock
[mysqld]
datadir=$mysql_data_dir
skip-name-resolve
log-error=$mysql_install_dir/3306erroe.log
pid-file=$mysql_install_dir/3306mysql.pid
lower_case_table_names=1
innodb_file_per_table=1
port = 3306
socket =$mysql_install_dir/mysql.sock
back_log = 50
max_connections = 300
max_connect_errors = 1000
table_open_cache = 2048
max_allowed_packet = 16M
binlog_cache_size = 2M
max_heap_table_size = 64M
sort_buffer_size = 2M
join_buffer_size = 2M
thread_cache_size = 64
thread_concurrency = 8
query_cache_size = 64M
query_cache_limit = 2M
ft_min_word_len = 4
default-storage-engine = innodb
thread_stack = 192K
transaction_isolation = REPEATABLE-READ
tmp_table_size = 64M
log-bin=mysql-bin     
binlog_format=mixed
slow_query_log
long_query_time = 1
server-id = 1        
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 2M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 200M
innodb_data_file_path = ibdata1:10M:autoextend
innodb_file_io_threads = 8
innodb_thread_concurrency = 16
innodb_flush_log_at_trx_commit = 1
innodb_log_buffer_size = 16M
innodb_log_file_size = 512M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 60
innodb_lock_wait_timeout = 120
[mysqldump]
quick
max_allowed_packet = 256M
[mysql]
no-auto-rehash
prompt=\\u@\\d \\R:\\m>
[myisamchk]
key_buffer_size = 512M
sort_buffer_size = 512M
read_buffer = 8M
write_buffer = 8M
[mysqlhotcopy]
interactive-timeout
[mysqld_safe]
open-files-limit = 8192
EOF
   else
   \cp -p my-default.cnf /etc/my.cnf
   fi
else 
   action "NO" /bin/false
   exit 1
fi
[ -f /usr/local/mysql/scripts/mysql_install_db ] &&\
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --basedir=$mysql_install_dir --datadir=$mysql_data_dir --user=mysql
##cp mysqld data
\cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig mysqld on
echo "export PATH=$mysql_install_dir/bin:\$PATH" >> /etc/profile && echo "export PATH" >> /etc/profile
.  /etc/profile
service mysqld start
source /etc/profile
}
MYSQL

View Code

#!/bin/sh
MYSQL_CMD_DOR=/etc
DATA=/data
MYSQL_DATA=/usr/local/mysql
MYSQL_BIN=/usr/local/mysql/bin
for PORT in 3306 3307 
    do
    mkdir -p $DATA/$PORT$DATA
    chown -R mysql:mysql $DATA
    \cp ${MYSQL_CMD_DOR}/my.cnf  $DATA/$PORT/

    sed -i "s/3306/${PORT}/g" $DATA/$PORT/my.cnf
    sed -i  s#${MYSQL_DATA}#$DATA/$PORT#g  $DATA/$PORT/my.cnf
    sed -i "s/^server-id = 1/server-id=`echo $PORT|cut -c 4-`/g" $DATA/$PORT/my.cnf
    chown -R mysql:mysql $DATA
    $MYSQL_DATA/scripts/mysql_install_db --basedir=$MYSQL_DATA --datadir=$DATA/$PORT$DATA --user=mysql
        chown -R mysql:mysql $DATA
    sleep 2
    $MYSQL_BIN/mysqld_safe --defaults-file=$DATA/$PORT/my.cnf &
    sleep 5
     netstat -ntlp|grep "$PORT"     
    echo 
    echo "---------step 2:chaneg mysql passwd--------------"
    sleep 5
    mysqladmin -uroot password \'123456\' -S  $DATA/$PORT/mysql.sock
    done 
    netstat -nltp|grep ${PORT}

View Code

 

版权声明:本文为liang2580原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/liang2580/articles/7789195.html