Shell自动化安装mysql-glibc
#!/bin/bash
while [ -f /usr/share/doc/libaio-0.3.109/COPYING
]
do
a
=`echo $?`
if [ $a -eq 0
];then
echo "依赖软件libaio已安装"
break
else
echo "正在安装libaio软件"
yum
install libaio -y
fi
done
while [ -f /usr/bin/wget
]
b
=`echo $?`
do
if [ $b -eq 0
];then
echo "wget软件已安装"
break
else
echo "正在安装wget软件"
yum
install wget -y
fi
done
wget https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
echo "正在解压mysql软件包请耐心等待~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
tar -zxf mysql-5.7.31-linux-glibc2.12-x86_64.tar.gz
echo "mysql-5.7.31软件包已解压完成"
useradd -r -s /sbin/nologin mysql
echo "mysql账号创建完成"
rm -rf /etc/my.cnf
echo "mariadb配置/etc/my.cnf已清空完毕"
mkdir /mysql_3306
mv /root/mysql-5.7.31-linux-glibc2.12-x86_64/* /mysql_3306
cd /mysql_3306
mkdir mysql-files
chown mysql:mysql mysql-files
chmod 750 mysql-files
bin/mysqld --initialize --user
=mysql --basedir
=/mysql_3306
>>/root/dic 2
>&1
bin/mysql_ssl_rsa_setup --datadir
=/mysql_3306/data
echo "安全加密连接已完成"
cp support-files/mysql.server /etc/init.d/mysql_3306
sed -ri
'/^basedir/c\basedir=/mysql_3306/' /etc/init.d/mysql_3306
sed -ri
'/^datadir/c\datadir=/mysql_3306/data' /etc/init.d/mysql_3306
service mysql_3306 start
chkconfig --add mysql_3306
chkconfig mysql_3306 on
echo "mysql数据库已启动并添加到开机启动项"
passwd
=`awk -F "host: " '/root@localhost/{print $2}' /root/dic`
yum
install expect -y
expect << EOF
cd /mysql_3306/
spawn bin/mysqladmin -uroot password 123456 -p
expect {
"Enter password:" { send "$passwd\r" };
}
expect eof
EOF
echo 'export PATH=$PATH:/mysql_3306/bin' >> /etc/profile
source /etc/profile
cat > /mysql_3306/my.cnf
<<EOF
[mysqld]
basedir=/mysql_3306
datadir=/mysql_3306/data
socket=/tmp/mysql.sock
EOF
echo "/mysql_3306/my.cnf已配置完成 正在重启"
expect << EOF
spawn mysql_secure_installation
expect {
"Enter password for user root:" { send "123456\r";exp_continue }
"Press y|Y for Yes, any other key for No:" { send \r;exp_continue }
"Change the password for root ? ((Press y|Y for Yes, any other key for No) :" { send "\r";exp_continue }
"Remove anonymous users? (Press y|Y for Yes, any other key for No) :" { send "y\r";exp_continue }
"Disallow root login remotely? (Press y|Y for Yes, any other key for No) :" { send "y\r";exp_continue }
"Remove test database and access to it? (Press y|Y for Yes, any other key for No) :" { send "y\r";exp_continue }
"Reload privilege tables now? (Press y|Y for Yes, any other key for No) :" { send "y\r";exp_continue };
}
expect eof
EOF
mysql -uroot -p
刚接触写的不好勿喷