注: mysql一件自动化安装,先把mysql源码包下载到/root下,再执行本脚本
#!/bin/bash#mysql_multi install #date 2017/8/22#author vaeditfunction mysql_install(){ useradd -M -s /sbin/nologin mysql tar xf mysql-5.5.57.tar.gz cd mysql-5.5.57 yum -y install gcc gcc-c++ cmake ncurses-devel libtool zilib-devel cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ -DMYSQL_DATADIR=/data/mysql/ -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_DEBUG=0 make && make install ln -s /usr/local/mysql/bin/* /usr/bin cp support-files/my-large.cnf /etc/my.cnf -f cp support-files/mysql.server /etc/rc.d/init.d/mysqld chmod 755 /etc/init.d/mysqld echo "开始初始化mysql实例" /usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/data/mysql --user=mysql echo "开始启动mysql" service mysqld start mysqladmin -u root password "123456"} #检查是否安装mysqlif [ -d /usr/local/mysql ];then read -p "改机器已安装过mysql程序,是否继续安装【yes/no】" enterelse enter="yes"fiif [ "$enter" == "yes" ];then mysql_install if [ $? -eq 0 ];then echo -e '\e[32;40;1mmysql安装成功\e[0m' exit 0 else echo -e '\e[31;40;1mmysql安装失败\e[0m' exit 1 fielse echo -e '\e[31;40;1mmysql安装失败\e[0m' exit 2 fi