mysql5.5一键安装脚本

环境:centos5.6+mysql-5.5.37                     mysql5.5以后都用cmake编译,需要安装cmake
因为mysql环境包蛮多,我们需要指定yum源。为了不影响网速我用的本地yum源,用163或官方yum源也是可以的
安装目录:/usr/local/mysql/
数据目录:/data/mysql/data/
二进制日志:/data/msyql/binlog/
relay日志:/data/mysql/relaylog/
配置文件:/data/mysql/my.cnf
mysql.sock文件:/data/mysql/mysql.sock
1、将cmake和mysql源码包弄到 /data/soft 目录内,配置好yum源
cmake下载地址    http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
mysql下载地址    ftp://mirror.switch.ch/mirror/my ... mysql-5.5.37.tar.gz



#!/bin/bash
#指定源码包目录、mysql数据目录、mysql安装目录
MYSQL_DIR="/data/soft"
DATA_DIR="/data/mysql/data"
BASE_DIR="/usr/local/mysql"

echo "please input mysql version:"
read VERSION
echo “"Your mysql version is mysql-$VERSION.tar.gz"

if [ -e "$MYSQL_DIR/mysql-$VERSION.tar.gz" ]
then
echo "Please waitting"
sleep 3
#Install mysql package dependent.
yum -y install gcc gcc-c++ gcc-g77 autoconf openssl zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* &&
#Install cmake
echo "The system is be install cmakemplease waitting..."
sleep 3
tar -zxvf $MYSQL_DIR/cmake-2.8.12.2.tar.gz -C $MYSQL_DIR &&
cd $MYSQL_DIR/cmake-2.8.12.2 &&
./configure --prefix=/usr/local/cmake && make && make install &&
#creating mysql account and group
/usr/sbin/groupadd mysql &&
/usr/sbin/useradd -s /sbin/nologin -g mysql -M mysql &&
#Install mysql.
tar -zxvf $MYSQL_DIR/mysql-$VERSION.tar.gz -C $MYSQL_DIR
cd $MYSQL_DIR/mysql-$VERSION
echo "PATH=$PATH:/usr/local/cmake/bin" >> /etc/profile && source /etc/profile
#编译mysql,可以按自己需求编译
cmake $MYSQL_DIR/mysql-$VERSION
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql
-DYSQL_TCP_PORT=3306
-DMYSQL_DATADIR=$DATA_DIR
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock
-DWITH_MYISAM_STORAGE_ENGING=1
-DWITH_INNOBASE_STORAGE_ENGINE=1  
-DDEFAULT_CHARSET=utf8  
-DDEFAULT_COLLATION=utf8_general_ci  
-DEXTRA_CHARSETS=all 
-DWITH_DEBUG=0
make && make install &&

mkdir -p $DATA_DIR
mkdir -p `dirname $DATA_DIR`/binlog
mkdir -p `dirname $DATA_DIR`/relaylog
cp $MYSQL_DIR/mysql-$VERSION/support-files/my-small.cnf.sh `dirname $DATA_DIR`/my.cnf
cp $MYSQL_DIR/mysql-$VERSION/support-files/mysql.server.sh /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
sed -i 's/^basedir=/basedir=\/usr\/local\/mysql/' /etc/init.d/mysqld
sed -i 's/^datadir=/datadir=\/data\/mysql\/data/' /etc/init.d/mysqld
sed -i 's/`@HOSTNAME@`/lqx.com/' /etc/init.d/mysqld
#初始化mysql
sh /usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=$DATA_DIR  &&
/etc/init.d/mysqld start
else
echo "Your input mysql version  is not in $MYSQL_DIR"
fi



执行脚本一键安装mysql
 

一键安装完成
 

检验
 

KO



你可能感兴趣的:(mysql,脚本,unix,mysql,linux,centos)