脚本代码如下:
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
tar xf mysql-5.7.33-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.33-linux-glibc2.12-x86_64 /usr/local/mysql
groupadd mysql
useradd -r -g mysql -s /bin/false mysql
service firewalld stop
systemctl disable firewalld
setenforce 0
sed -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config
mkdir /data/mysql -p
chown mysql:mysql /data/mysql/
chmod 750 /data/mysql/
cd /usr/local/mysql/bin/
./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql &>passwd.txt
./mysql_ssl_rsa_setup --datadir=/data/mysql/
tem_passwd=$(cat passwd.txt |awk '/temporary/{print $NF}')
export PATH=/usr/local/mysql/bin/:$PATH
echo 'PATH=/usr/local/mysql/bin:$PATH' >>/root/.bashrc
cp ../support-files/mysql.server /etc/init.d/mysqld
sed -i '70c datadir=/data/mysql' /etc/init.d/mysqld
cat >/etc/my.cnf <<EOF
[mysqld_safe]
[client]
socket=/data/mysql/mysql.sock
[mysqld]
socket=/data/mysql/mysql.sock
port = 3306
open_files_limit = 8192
innodb_buffer_pool_size = 512M
character-set-server=utf8
[mysql]
auto-rehash
prompt=\\u@\\d \\R:\\m mysql>
EOF
service mysqld start
/sbin/chkconfig --add mysqld
/sbin/chkconfig mysqld on
mysql -uroot -p$tem_passwd --connect-expired-password -e "set password='123456';"
mysql -uroot -p'123456' -e "show databases;"