[shell]一键配置安装MySQL5.6.40

 黑渐神|he-jason.com   2018-11-22 18:49   4,726 人阅读  [shell]一键配置安装MySQL5.6.40已关闭评论

一键配置MySQL5.6.40到/application/mysql

#!/usr/bin/sh
auth:jason
data:2018-11-11
mysqlpath="/application/mysql"
#下载二进制包
curl https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
#安装依赖
yum install -y perl autoconf libaio &>>/dev/null
echo '正在解压MySQL-5.6.40...'
tar xf mysql-5.6.40-linux-glibc2.12-x86_64.tar.gz
mkdir /application
mv mysql-5.6.40-linux-glibc2.12-x86_64 /application/mysql-5.6.40
ln -s /application/mysql-5.6.40 /application/mysql
id mysql
#判断是否有mysql用户,如果没有,创建该用户,有就不执行里面的内容
if test $? -ne 0 ;then
    useradd mysql -M -s /usr/sbin/nologin
fi
/application/mysql/scripts/mysql_install_db --user=mysql --basedir=/application/mysql --datadir=/application/mysql/data &>>/dev/null
if test $? -ne 0 ;then
    echo "MySQL初始化出错,请检查环境..."
    exit 1
fi
cp $mysqlpath/support-files/my-default.cnf /etc/my.cnf
cp $mysqlpath/support-files/mysql.server /etc/init.d/mysqld
sed -i 's#/usr/local#/application#g' /etc/init.d/mysqld $mysqlpath/bin/mysqld_safe
echo 'export PATH=/application/mysql/bin:$PATH' >>/etc/profile
export PATH=/application/mysql/bin:$PATH
chown -R mysql.mysql /application/mysql-5.6.40
echo 'basedir=/application/mysql' >>/etc/my.cnf
echo 'datadir=/application/mysql/data' >>/etc/my.cnf
#把MySQL加入systemctl 管理
cat <<'EOF' >>/etc/systemd/system/mysqld.service
[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=/application/mysql/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE = 5000
EOF
#重载systemctl 启动MySQL服务
systemctl daemon-reload
systemctl start mysqld
echo "MySQL已经安装到/application/mysql下,请留意!"
本文地址:https://www.he-jason.com/linuxbasic/script_language/shell/478.html
版权声明:本文为原创文章,版权归 黑渐神|he-jason.com 所有,欢迎分享本文,转载请保留出处!
双11拉新分百万红包

评论已关闭!