开发自动化脚本一键安装MySQL数据库

环境:

[root@localhost ~]# cat /etc/redhat-release

CentOS release 6.6 (Final)

[root@localhost ~]# uname -m

x86_64

 

脚本:

 

#!/bin/bash
 
#created by teddylu on 2015-7-7
 
#used for mysql auto installation
 
 
 
MySQl_Soft_Dir="/soft"
 
MySQL_Version=5.5.44
 
 
 
#Source function library
 
. /etc/init.d/functions
 
#install related soft
 
yum install -y wget gcc gcc-c++ gcc-g77 autoconf automake zlib* fiex* libxml* ncurses-devel libmcrypt* libtool-ltdl-devel* cmake bison
 
 
 
echo "-------step1:add mysql account-------"
 
groupadd mysql
 
useradd -s /sbin/nologin -g mysql -M mysql
 
 
 
 
 
sleep 1
 
 
 
echo "-------step2:download mysql-------"
 
mkdir -p ${MySQl_Soft_Dir}
 
cd ${MySQl_Soft_Dir}
 
wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.44.tar.gz
 
 
 
echo "-------step3:install mysql-------"
 
cd ${MySQl_Soft_Dir}
 
tar zxf mysql-5.5.44.tar.gz
 
cd mysql-5.5.44
 
 
 
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \
 
-DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \
 
-DDEFAULT_CHARSET=utf8 \
 
-DDEFAULT_COLLATION=utf8_general_ci \
 
-DWITH_EXTRA_CHARSETS:STRING=utf8,gbk \
 
-DWITH_MYISAM_STORAGE_ENGINE=1 \
 
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
 
-DWITH_READLINE=1 \
 
-DENABLED_LOCAL_INFILE=1 \
 
-DMYSQL_DATADIR=/usr/local/mysql/data
 
if [ $? -ne 0 ];then
 
?? action "mysql configure" /bin/false
 
?? exit 1
 
fi
 
 
 
make
 
if [ $? -ne 0 ];then
 
?? action "mysql make" /bin/false
 
?? exit 1
 
fi
 
 
 
make install
 
if [ $? -ne 0 ];then
 
?? action "mysql make install" /bin/false
 
?? exit 1
 
fi
 
 
 
action "MySQL is installed OK!!!" /bin/true
 
 
 
#setup permission of the mysql and mysql config file
 
chmod -R 755 /usr/local/mysql/
 
chown -R mysql.mysql /usr/local/mysql/
 
cp support-files/my-large.cnf /etc/my.cnf
 
 
 
# initialize mysql
 
/usr/local/mysql/scripts/mysql_install_db \
 
--basedir=/usr/local/mysql \
 
--datadir=/usr/local/mysql/data \
 
--user=mysql
 
 
 
#setup mysql startup script
 
cp /soft/mysql-5.5.44/support-files/mysql.server /etc/init.d/mysqld
 
chmod 700 /etc/init.d/mysqld
 
 
 
#setup mysql global variable path
 
echo 'export PATH=$PATH:/usr/local/mysql/bin'>>/etc/profile
 
source /etc/profile
 
 
 
#setup the passwd for mysql root
 
pass1=`openssl rand 6 -base64`
 
echo "happy.${pass1}"
 
echo "mysql-pass=happy.${pass1}" && >> /root/pass.txt
 
/etc/init.d/mysqld start
 
mysqladmin -u root password "happy.${pass1}"
 
 
 
#setup mysql start when system start
 
chkconfig --add mysqld
 
chkconfig mysqld on
 
 
 
#restart mysql
 
/etc/init.d/mysqld restart
此条目发表在MySql, Shell分类目录,贴了标签。将固定链接加入收藏夹。