不懂?没有人会嘲笑你;装懂?人人鄙视你;不懂,先研究;再不懂,就问吧!

mysql一键安装shell脚本

mysql xjmroots 2380℃ 2评论

一键安装mysql,就是这么简单

#!/bin/bash
#时间:2014-5-4
#作者:谢家明
#指定源码包目录、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一键安装shell脚本

喜欢 (0)or分享 (0)
发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
(2)个小伙伴在吐槽
  1. [欢迎] 感谢分享,希望博主再接再厉
    lqxming2014-05-31 00:05 回复
  2. 正解
    路人2014-06-05 00:28 回复