mysql -- 5.6 安装脚本--guo

mysql -- 5.6 guo
#!/bin/bash
#
# 设置MySQL管理员账号密码
PASSWORD=123456
clear
# 判断脚本执行者是否为root用户
if [ "`whoami`" != "root" ];then
  echo "请用以root用户身份执行该脚本!" 
  exit 1
fi

# 交互提示是否确认进行安装
echo "------欢迎使用MySQL 5.6版一键安装脚本 V1.0------"
echo "注意事项:"
echo "1.在安装过程中请保证网络畅通!"
echo "2.请使用source命令执行脚本"
echo ""
while true;do
read -p "是否进行开始安装?(y/n)" a
if [ $a = y ];then
  echo "开始为您安装MySQL5.6..."
  break
 elif [ $a = n ];then
  echo "已取消安装"
  exit 1
 else
  echo "输入有误,请重新输入!" 
fi
done

# MySQL安装开始
yum -y install ncurses-devel gcc-c++ perl-Module-Install expect
tar zxvf /opt/mysql-5.6.36.tar.gz -C /opt
tar zxvf /opt/cmake-2.8.6.tar.gz -C /opt
cd /opt/cmake-2.8.6
./configure
gmake && gmake install
cd /opt/mysql-5.6.36
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYCONFDIR=/etc
make && make install
cd /opt/mysql-5.6.36
/usr/bin/expect <<-EOF
spawn cp support-files/my-default.cnf /etc/my.cnf
expect {
  "?" 
  {send "yes\r";}
}
EOF
cp /opt/mysql-5.6.36/support-files/mysql.server /etc/rc.d/init.d/mysqld
chmod +x /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
echo "PATH=$PATH:/usr/local/mysql/bin" >> /etc/profile
source /etc/profile
groupadd mysql
useradd -M -s /sbin/nologin mysql -g mysql
chown -R mysql.mysql /usr/local/mysql
mkdir -p /data/mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
systemctl start mysqld && systemctl enable mysqld

#免交互设置MySQL管理员密码
/usr/bin/expect <<-EOF
spawn mysqladmin -u root -p password "$PASSWORD" 
expect {
  ":" 
  {send "\r";}
}
expect eof
EOF

echo "MySQL 5.6 已安装!"

mysql -- 5.6 安装脚本--guo

上一篇:Centos 7 安装 mysql 8


下一篇:mysql 5.7 用户添加与权限管理