#!/bin/bash
SOFT=/data2/software
B=/dev/null
SQL=/usr/local/webserver/MySQL
SQLDIR=/data0/mysql/3306
PATHROOT=/usr/local/webserver
! [ -e $SQLDIR ] && mkdir -p $SQLDIR/{data,binlog,relaylog}
! [ -e $PATHROOT ] && mkdir -p $PATHROOT
echo"downloading msyql-5.5...please wait a moment..."
cd $SOFT
wget http://mirror.trouble-free.net/mysql_mirror/Downloads/MySQL-5.5/mysql-5.5.25a.tar.gz
wget http://www.cmake.org/files/v2.8/cmake-2.8.6.tar.gz
! id mysql && groupadd -r mysql && useradd -r -g mysql -M -s /sbin/nologin mysql &> $B
tar xf cmake-2.8.6.tar.gz
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
cd cmake-2.8.6
./configure
make
make install
cd ..
tar xf mysql-5.5.25a.tar.gz
cd mysql-5.5.25a
cmake -DCMAKE_INSTALL_PREFIX=$SQL -DMYSQL_DATADIR=/data0/mysql/3306/data/ -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DENABLED_LOCAL_INFILE=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all-DMYSQL_TCP_PORT=3306 -DWITH_DEBUG=OFF-DWITH_READLINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock
make
make install
cd $ SQL
cp support-files/my-medium.cnf /data0/mysql/3306/data/my.cnf
cp /usr/local/webserver/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib64/libmysqlclient.so.18
chown -R mysql:mysql ./* $SQLDIR
chmod +w $SQL
$SQL/scripts/mysql_install_db--basedir=$SQL --datadir=$SQLDIR/data --user=mysql
cat >>$SQLDIR/my.cnf<
[client]
character-set-server = utf8
port = 3306
socket = /tmp/mysql.sock
[mysqld]
character-set-server = utf8
replicate-ignore-db = mysql
replicate-ignore-db = test
replicate-ignore-db = information_schema
user= mysql
port = 3306
socket = /tmp/mysql.sock
basedir = /usr/local/webserver/mysql
datadir = /data0/mysql/3306/data
log-error = /data0/mysql/3306/mysql_error.log
pid-file = /data0/mysql/3306/mysql.pid
open_files_limit = 10240
back_log = 600
max_connections = 5000
max_connect_errors = 6000
table_cache = 614
external-locking =FALSE
max_allowed_packet = 32M
sort_buffer_size = 1M
join_buffer_size = 1M
thread_cache_size = 300
#thread_concurrency = 8
query_cache_size = 512M
query_cache_limit = 2M
query_cache_min_res_unit = 2k
default-storage-engine = MyISAM
thread_stack = 192K
transaction_isolation =READ-COMMITTED
tmp_table_size = 246M
max_heap_table_size = 246M
long_query_time = 3
log-slave-updates
log-bin = /data0/mysql/3306/binlog/binlog
binlog_cache_size = 4M
binlog_format = MIXED
max_binlog_cache_size = 8M
max_binlog_size = 1G
relay-log-index= /data0/mysql/3306/relaylog/relaylog
relay-log-info-file = /data0/mysql/3306/relaylog/relaylog
relay-log = /data0/mysql/3306/relaylog/relaylog
expire_logs_days = 30
key_buffer_size = 256M
read_buffer_size = 1M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 64M
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
myisam_recover
interactive_timeout = 120
wait_timeout = 120
skip-name-resolve
#master-connect-retry = 10
slave-skip-errors = 1032,1062,126,1114,1146,1048,1396
#master-host = 192.168.1.2
#master-user= username
#master-password=password
#master-port = 3306
server-id = 1
innodb_additional_mem_pool_size = 16M
innodb_buffer_pool_size = 512M
innodb_data_file_path = ibdata1:256M:autoextend
innodb_file_io_threads = 4
innodb_thread_concurrency = 8
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 16M
innodb_log_file_size = 128M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120
innodb_file_per_table = 0
#log-slow-queries = /data0/mysql/3306/slow.log
#long_query_time = 10
[mysqldump]
quick
max_allowed_packet = 32M
EOF
mkdir -pv /usr/local/mysql/bin
chmod +x $SQLDIR/mysql
ln -sv $SQL/bin/* /usr/local/mysql/bin &> $B
ln -sv $SQL/include /usr/include/mysql
ldconfig
service mysqld start
if netstat -tnlp|grep mysqld &> /dev/null;then
echo"mysql-5.5 install success..."
fi