主要功能如下:
-d download software 下载需要的MySQL安装包,编辑脚本在download函数内修改
-c setup cmake $0 -c filename 安装cmake,使用方法为:脚本名+参数+文件名(不包含.tar.gz)
-h setup mysql 5.0.x $0 -h filename安装mysql5.0.x,使用方法为:脚本名+参数+文件名(不包含.tar.gz)
-i config mysql 5.0.x 配置mysql 5.0
-j setup mysql 5.5.x $0 -j filename 安装mysql5.5.x,使用方法为:脚本名+参数+文件名(不包含.tar.gz)
-k config mysql 5.5.x配置mysql 5.5
安装之后,
1,需要手动修改/etc/init.d/mysql.server文件,添加basedir和datadir
2,需要添加/etc/my.cnf配置文件
- #!/bin/bash
- # email:
- # last change time: 2011-08-17
- set -e
- set -u
- #TIME=`date +%Y%m%d%H%M%S`
- DIR_MYSQL='/usr/local/mysql'
- function download()
- {
- yum install gcc gcc-c++ ncurses-devel bison
- wget
- wget
- #wget http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.92.tar.gz/from/http://mysql.mirrors.pair.com/
- exit 0
- }
- function usage_error()
- {
- echo "error!!"
- echo "
- -d download software
- -c setup cmake $0 -c filename
- -h setup mysql 5.0.x $0 -h filename
- -i config mysql 5.0.x
- -j setup mysql 5.5.x $0 -j filename
- -k config mysql 5.5.x
- "
- exit 1
- }
- function setup_status()
- {
- sleep 3
- if [ $? -ne 0 ]; then
- exit 1
- fi
- }
- function setup_m50()
- {
- id mysql
- if [ $? -ne 0 ]; then
- # Preconfiguration setup
- groupadd mysql
- useradd -g mysql mysql
- fi
- if [ -e ${OPTARG}.tar.gz ];then
- # Beginning of source-build specific instructions
- tar -zxf ${OPTARG}.tar.gz
- setup_status
- cd ${OPTARG}
- else
- usage_error
- fi
- ./configure --prefix=${DIR_MYSQL} \
- --datadir=${DIR_MYSQL}/data \
- --without-debug \
- --without-bench \
- --enable-thread-safe-client \
- --enable-assembler \
- --with-mysqld-ldflags=-all-static \
- --with-client-ldflags=-all-static \
- --with-charset=utf8 \
- --with-collation=utf8_bin \
- --with-innodb
- setup_status
- make
- setup_status
- make install
- setup_status
- # End of source-build specific instructions
- }
- function configure_m50()
- {
- # Post installation setup
- cd ${DIR_MYSQL}
- chown -R mysql .
- chgrp -R mysql .
- bin/mysql_install_db --user=mysql --datadir=${DIR_MYSQL}/data
- setup_status
- chown -R root .
- chown -R mysql data
- # Next command is optional, used default mysqlserver config
- if [ -e /etc/my.cnf ]; then
- mv /etc/my.cnf /etc/my.cnf.${TIME}
- fi
- bin/mysqld_safe --user=mysql &
- setup_status
- if [ ! -e /etc/init.d/mysql.server ]; then
- cp ${DIR_MYSQL}/data/mysql/mysql.server /etc/init.d/mysql.server
- chmod +x /etc/init.d/mysql.server
- fi
- }
- function setup_cmake()
- {
- tar -xzf ${OPTARG}.tar.gz
- cd ${OPTARG}
- ./configure
- setup_status
- make
- setup_status
- make install
- }
- function setup_m55()
- {
- id mysql
- if [ $? -ne 0 ]; then
- # Preconfiguration setup
- groupadd mysql
- useradd -g mysql mysql
- fi
- if [ -e ${OPTARG}.tar.gz ];then
- # Beginning of source-build specific instructions
- tar -zxf ${OPTARG}.tar.gz
- cd ${OPTARG}
- else
- usage_error
- fi
- /usr/local/bin/cmake . -DCMAKE_INSTALL_PREFIX=$DIR_MYSQL\
- -DMYSQL_DATADIR=$DIR_MYSQL/data\
- -DMYSQL_UNIX_ADDR=$DIR_MYSQL/data/mysql.sock\
- -DINSTALL_LAYOUT=STANDALONE\
- -DDEFAULT_CHARSET=utf8\
- -DDEFAULT_COLLATION=utf8_general_ci\
- -DEXTRA_CHARSETS=all\
- -DWITH_INNOBASE_STORAGE_ENGINE=1\
- -DWITH_READLINE=1\
- -DENABLED_LOCAL_INFILE=1\
- -DMYSQL_TCP_PORT=3306\
- -DWITH_DEBUG=0
- setup_status
- make
- setup_status
- make install
- setup_status
- # End of source-build specific instructions
- }
- function configure_m55()
- {
- # Post installation setup
- cd ${DIR_MYSQL}
- chown -R mysql .
- chgrp -R mysql .
- scripts/mysql_install_db --user=mysql --datadir=${DIR_MYSQL}/data
- setup_status
- chown -R root .
- chown -R mysql data
- # Next command is optional, used default mysqlserver config
- if [ -e /etc/my.cnf ]; then
- mv /etc/my.cnf /etc/my.cnf.${TIME}
- fi
- bin/mysqld_safe --user=mysql &
- setup_status
- if [ ! -e /etc/init.d/mysql.server ]; then
- cp ${DIR_MYSQL}/support-files/mysql.server /etc/init.d/mysql.server
- chmod +x /etc/init.d/mysql.server
- fi
- }
- if [ $# -eq 0 ]; then
- usage_error
- else
- while getopts :dc:h:i:j arg
- do
- case $arg in
- d)
- download
- ;;
- c)
- setup_cmake
- ;;
- h)
- setup_m50
- ;;
- i)
- configure_m50
- ;;
- j)
- setup_m55
- ;;
- k)
- configure_m55
- ;;
- :)
- echo "$arg: 缺少参数"
- usage_error
- ;;
- \?)
- echo "$arg: 非法选项"
- usage_error
- ;;
- esac
- done
- fi