#!/bin/bash
[ -f /tmp/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz ] && rm -rf /tmp/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
wget -O /tmp/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz
yum -y install gcc gcc-c++ cmake ncurses-devel libaio-devel autoconf openssl openssl-devel
[ -d /tmp/mysql-5.6.46-linux-glibc2.12-x86_64 ] && rm -rf /tmp/mysql-5.6.46-linux-glibc2.12-x86_64
tar xf /tmp/mysql-5.6.46-linux-glibc2.12-x86_64.tar.gz -C /tmp/
[ -d /usr/local/mysql-5.6.46 ] && rm -rf /usr/local/mysql-5.6.46
mv /tmp/mysql-5.6.46-linux-glibc2.12-x86_64 /usr/local/mysql-5.6.46
rm -rf /usr/local/mysql && ln -s /usr/local/mysql-5.6.46 /usr/local/mysql
useradd -M -s /sbin/nologin mysql 2> /dev/null
\cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf
\cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data/
cat>/usr/lib/systemd/system/mysqld.service<<EOF
[Unit]
Description=MySQL Server
Documentation=man:mysqld(8)
Documentation=https://dev.mysql.com/doc/refman/en/using-systemd.html
After=network.target
After=syslog.target
[Install]
WantedBy=multi-user.target
[Service]
User=mysql
Group=mysql
ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF
systemctl daemon-reload
systemctl start mysqld.service
systemctl enable mysqld.service
echo "export PATH=/usr/local/mysql/bin:\$PATH" > /etc/profile.d/mysql.sh
source /etc/profile