教程集 www.jiaochengji.com
教程集 >  脚本编程  >  shell  >  正文 mysql 5.1自动安装的shell脚本

mysql 5.1自动安装的shell脚本

发布时间:2014-11-18   编辑:jiaochengji.com
分享一段shell脚本,实现mysql 5.1数据库的自动安装,有需要的朋友参考下。

在编译方式安装与部署mysql时,一遍遍地输入命令,过程太繁琐。
因此,写了一个shell脚本来自动完成mysql的安装过程。

以下脚本,可以实现自动化安装mysql 5.1.63。

大家可以下载my.cnf文件解压后和脚本放统一目录下,执行安装脚本即可。

代码:
 

复制代码 代码示例:

#!/bin/bash
echo "-----------------------start install mysql----------------------"
yum -y install gcc gcc-c++ ncurses ncurses-devel openssl openssl-devel libtool*
mkdir -p /data/dbdata
if [ `grep "mysql" /etc/passwd | wc -l` -eq 0 ];then
echo "adding user mysql"
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
else
echo "mysql user is exist"
fi

wget http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.63.tar.gz
echo "tar xzvf mysql-5.1.63.tar.gz"
tar xzvf mysql-5.1.63.tar.gz
cd mysql-5.1.63
echo "configuring mysql,please wait-----------------"
./configure '--prefix=/usr/local/mysql' '--localstatedir=/data/dbdata/' '--with-unix-socket-path=/usr/local/mysql/tmp/mysql.sock' '--with-charset=utf8' '--with-extra-charsets=complex' '--with-pthread' '--enable-thread-safe-client' '--with-ssl' '--with-client-ldflags=-all-static' '--with-mysqld-ldflags=-all-static' '--with-plugins=partition,federated,innobase,csv,blackhole,myisam,innodb_plugin,heap,archive' '--enable-shared' '--enable-assembler'

if [ $? -ne 0 ];then
echo "configure filed ,please check it out!"
exit 1
fi

echo "make mysql, please wait for 20 minutes"
make
if [ $? -ne 0 ];then
echo "make filed ,please check it out!"
exit 1
fi

make install

chown -R mysql:mysql /usr/local/mysql
chown -R mysql.mysql /data/dbdata/

/usr/local/mysql/bin/mysql_install_db --user=mysql

cp ../my.cnf /etc/my.cnf

cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --level 2345 mysqld on

echo "mysql starting"
/etc/rc.d/init.d/mysqld start
if [ $? -ne 0 ];then
echo "mysql start filed ,please check it out!"
else
echo "mysql start successful,congratulations!"
fi

附,my.cnf文件下载地址。

您可能感兴趣的文章:
mysql 5.1自动安装的shell脚本
linux下mysql 5.5.8 源码编译安装
linux 下mysql自动备份的shell脚本
mysql备份与同步脚本
自动安装mysql数据库的shell脚本
实现DHCP自动化安装的shell脚本
Ubuntu 11.10安装MySQL 5.5.x版本
Linux Apache Mysql PHP典型配置
Ubuntu下安装搭建MySQL环境步骤介绍
实现远程MySQL自动查询的shell脚本

[关闭]
~ ~