lnmp一键安装 mysql升级_lnmp一键安装之-mysql

#!/bin/bash

#version 1.0

#date    2013-03-21

#author  yangcan

#mail    yoncan@qq.com

_work_path=$(pwd)

_mysql_path=/usr/local/mysql

_mysql_data_path=/home/var

_mysql_passwd=yangcan

_user=mysql

_cmake_soft="cmake-2.8.10.2"

_bison_soft="bison-2.7"

_mysql_soft="mysql-5.5.31"

_CHECK_STATS() {

if [ $? == 0 ];then

echo "*************************************" >>$_work_path/install.log

echo "$1 : at $(date +'%F %T') install OK "  >>$_work_path/install.log

else

echo "install mysql error. please cat $_work_path/install.log "

echo "*************************************" >>$_work_path/install.log

echo "$1 : at $(date +'%F %T') install               <> "  >>$_work_path/install.log

exit 1

fi

}

CHECK_FILE() {

( yum grouplist|grep -B 100 "Available Groups:"|grep "Development Libraries" ) || yum groupinstall "Development Libraries"

( yum grouplist|grep -B 100 "Available Groups:"|grep "Development Tools" ) || yum groupinstall "Development Tools"

yum install gcc gcc-c++ ncurses-devel make wget -y

[ -s $_cmake_soft.tar.gz ] || wget  http://www.cmake.org/files/v2.8/$_cmake_soft.tar.gz

[ -s $_bison_soft.tar.gz ] || wget  http://mirror.bjtu.edu.cn/gnu/bison/$_bison_soft.tar.gz

[ -s $_mysql_soft.tar.gz ] || wget  http://cdn.mysql.com/Downloads/MySQL-5.5/$_mysql_soft.tar.gz

}

INSTALL_DEPTH() {

cd $_work_path

tar -zxf $_cmake_soft.tar.gz

cd ${_cmake_soft}

./bootstrap

make && make install

_CHECK_STATS $_cmake_soft

cd $_work_path

tar -zxf $_bison_soft.tar.gz

cd ${_bison_soft}

./configure

make && make install

_CHECK_STATS $_bison_soft

}

INSTALL_MYSQL() {

cd $_work_path

tar -zxf $_mysql_soft.tar.gz

[ $(id mysql > /dev/null 2>&1) ] || useradd -M -r -s /sbin/nologin mysql

cd ${_mysql_soft}

cmake -DCMAKE_INSTALL_PREFIX=$_mysql_path  \

-DSYSCONFDIR=/etc \

-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \

-DDEFAULT_CHARSET=utf8 \

-DDEFAULT_COLLATION=utf8_general_ci \

-DWITH_EXTRA_CHARSETS=all \

-DWITH_MYISAM_STORAGE_ENGINE=1 \

-DWITH_INNOBASE_STORAGE_ENGINE=1 \

-DWITH_FEDERATED_STORAGE_ENGINE=1 \

-DWITH_PARTITION_STORAGE_ENGINE=1 \

-DWITH_READLINE=1 \

-DENABLED_LOCAL_INFILE=1 \

-DMYSQL_DATADIR=$_mysql_data_path \

-DWITH_DEBUG=0

_CHECK_STATS mysql_config

make  && make install

_CHECK_STATS mysql_make

}

CONFIG_MYSQL() {

cd ${_mysql_soft}

[ ! -d  $_mysql_data_path ] && mkdir -p $_mysql_data_path

[ id mysql >/dev/null 2>&1 ] || useradd -M -r -s /sbin/nologin $_user

chown -R $_user:$_user $_mysql_data_path

chown -R $_user:$_user $_mysql_path

echo  "$_mysql_path/lib"  >>/etc/ld.so.conf && ldconfig

ln -s $_mysql_path/bin/* /usr/local/bin/

cp -a support-files/mysql.server /etc/init.d/mysqld && chmod a+x /etc/init.d/mysqld

sed -i "s#\(^basedir=\).*#\1$_mysql_path#g" /etc/init.d/mysqld

sed -i "s#\(^datadir=\).*#\1$_mysql_data_path#g" /etc/init.d/mysqld

chkconfig --add mysqld

chkconfig  mysqld on

[ -f /etc/my.cnf ] && mv /etc/my.cnf{,.bak}

cat > /etc/my.cnf <

[client]

port                    = 3306

socket                  = /tmp/mysql.sock

[mysqld]

port                    = 3306

socket                  = /tmp/mysql.sock

character-set-server    = utf8

basedir                 = ${_mysql_path}

datadir                 = ${_mysql_data_path}

general_log_file        = ${_mysql_data_path}/mysqld.log

pid-file                = ${_mysql_data_path}/mysqld.pid

log-error               = ${_mysql_data_path}/mysqld.err

user                    = mysql

default-storage-engine  = MyISAM

key_buffer_size         = 256M

max_allowed_packet      = 20M

table_open_cache        = 256

sort_buffer_size        = 1M

read_buffer_size        = 1M

join-buffer-size        = 1M

read_rnd_buffer_size    = 4M

thread-cache-size       = 300

query-cache-size        = 512M

query-cache-limit       = 2M

query-cache-min-res-unit = 2k

transaction-isolation   = REPEATABLE-READ

thread-stack            = 192K

tmp-table-size          = 256M

max-heap-table-size     = 256M

long-query-time         = 3

skip-name-resolve

open-files-limit        = 10240

table-cache             = 614

table-open-cache        = 600

back-log                = 500

max-connections         = 5000

max-connect-errors      = 100

max-user-connections    = 100

external-locking        = FALSE

interactive-timeout     = 120

wait-timeout            = 120

# myisam engine

myisam_sort_buffer_size = 64M

myisam-sort-buffer-size = 128M

myisam-max-sort-file-size = 10G

myisam-repair-threads   = 2

myisam-recover-options

# Try number of CPU's*2 for thread_concurrency

thread_concurrency = 4

server-id               = 1

log-bin                 = mysql-bin

expire-logs-days        = 30

binlog-cache-size       = 4M

binlog-format           = MIXED

max-binlog-cache-size   = 8M

max-binlog-size         = 1G

# Uncomment the following if you are using InnoDB tables

#innodb_data_home_dir            = ${_mysql_data_path}

#innodb_data_file_path           = ibdata1:10M:autoextend

#innodb_log_group_home_dir       = ${_mysql_data_path}

# You can set .._buffer_pool_size up to 50 - 80 %

# of RAM but beware of setting memory usage too high

#innodb_buffer_pool_size = 256M

#innodb_additional_mem_pool_size = 20M

# Set .._log_file_size to 25 % of buffer pool size

#innodb_log_file_size            = 64M

#innodb_log_buffer_size          = 8M

#innodb-log-files-in-group       = 3

#innodb_flush_log_at_trx_commit  = 2

#innodb_lock_wait_timeout        = 50

#innodb-file-io-threads          = 4

#innodb-additional-mem-pool-size = 16M

#innodb-max-dirty-pages-pct      = 90

#innodb-lock-wait-timeout        = 120

#innodb-file-per-table           = FALSE

[mysqldump]

quick

max_allowed_packet      = 16M

[mysql]

no-auto-rehash

[myisamchk]

key_buffer_size         = 128M

sort_buffer_size        = 128M

read_buffer             = 2M

write_buffer            = 2M

[mysqlhotcopy]

interactive-timeout

[safe_mysqld]

err-log                 = ${_mysql_data_path}/mysqld.log

END_OF

$_mysql_path/scripts/mysql_install_db --defaults-file=/etc/my.cnf  --basedir=$_mysql_path --datadir=$_mysql_data_path

/etc/init.d/mysqld start

$_mysql_path/bin/mysqladmin -u root password"$_mysql_passwd"

/etc/init.d/mysqld restart

$_mysql_path/bin/mysql -uroot -p$_mysql_passwd -e "delete from mysql.user where Password=' '"

_CHECK_STATS mysql_configure

}

if [ `id -u` -ne 0 ];then

echo "install mysql need root"

exit 1

else

CHECK_FILE

INSTALL_DEPTH

INSTALL_MYSQL

CONFIG_MYSQL

[ $? -eq 0 ] && echo " $(date +"%F %T")  @@@@@@@ MYSQL COMPLETE  @@@@@@ " >> $_work_path/install.log

sleep 5

fi

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值