二进制安装mysql脚本_centos7二进制安装mysql5.6.50脚本

这是一个用于在CentOS7上二进制安装MySQL5.6.50的详细脚本。首先,它安装必要的依赖,然后下载并解压MySQL软件包,创建用户和数据目录,配置初始化数据库,设置环境变量,并启用启动服务。最后,脚本提供了一个安全加固的选项,包括设置root密码和限制远程访问。
摘要由CSDN通过智能技术生成

#/bin/bash

DIR=/usr/local/src

NAME="mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz"

FILE=$(echo $NAME|sed -r 's/(.*).tar.gz/\1/')

FULL_NAME=${DIR}/${NAME}

DATA_DIR="/data/mysql"

LINK="https://mirrors.tuna.tsinghua.edu.cn/mysql/downloads/MySQL-5.6/mysql-5.6.50-linux-glibc2.12-x86_64.tar.gz"

. /etc/init.d/functions

echo -e "\e[1;31m 下载依赖\e[0m"

yum -y install autoconf libaio-devel net-tools vim wget gcc gcc-c++ lrzsz &>/dev/null

if [ -h /usr/local/mysql ];then

action "mysql已经安装" false

exit 3

elif [ ! -f $FULL_NAME ];then

cd $DIR

echo -e "\e[1;31m下载软件包...\e[0m"

wget $LINK

echo -e "\e[1;31m解压中...\e[0m"

tar xf $FULL_NAME -C /usr/local/src &>/dev/null

else

echo -e "\e[1;31m解压中...\e[0m"

tar xf $FULL_NAME -C /usr/local/src &>/dev/null

ln -s /usr/local/src/$FILE /usr/local/mysql

fi

echo -e "\e[1;31m安装中...\e[0m"

#创建用户mysql

id mysql &>/dev/null && usermod -u306 -md /data/mysql -s /sbin/nologin mysql &>/dev/null || useradd -r -u306 -d /data/mysql -s /sbin/nologin mysql

chown -R mysql.mysql /usr/local/mysql/*

cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

chkconfig --add mysqld

cat > /etc/my.cnf <

[client]

socket=/data/mysql/mysql.sock

[mysql]

prompt=(\\u@\\h \\p) [\\d]>\\_

[mysqld]

user=mysql

datadir=/data/mysql

basedir=/usr/local/mysql

port=3306

socket=/data/mysql/mysql.sock

symbolic-links=0

log-error=/data/mysql/mysql.log

pid-file=/data/mysql/mysql.pid

EOF

cat >> /etc/profile.d/path.sh <

#mysql

export PATH=/usr/local/mysql/bin:\$PATH

EOF

. /etc/profile.d/path.sh

/usr/local/mysql/scripts/mysql_install_db --user=mysql --datadir=/data/mysql --basedir=/usr/local/mysql &>/dev/null

cat >/lib/systemd/system/mysqld.service <

[Unit]

Description=mysql database server

Documentation=man:mysqld(8)

Documentation=https://mariadb.com/kb/en/library/systemd/

After=network.target

[Install]

WantedBy=multi-user.target

Alias=mysqld.service

[Service]

Type=notify

PrivateNetwork=false

Type=forking

Restart=no

TimeoutSec=5min

IgnoreSIGPIPE=no

KillMode=process

GuessMainPID=no

RemainAfterExit=yes

SuccessExitStatus=5 6

ExecStart=/etc/rc.d/init.d/mysqld start

ExecStop=/etc/rc.d/init.d/mysqld stop

ExecReload=/etc/rc.d/init.d/mysqld reload

EOF

action "安装完成"

systemctl enable mysqld &>/dev/null

systemctl restart mysqld && ss -lnt|awk -F":| +" '/3306/{print $5}' && action "启动成功" || action "失败" false

#安全加固初始化 设置root密码123456 不允许远程登录

#echo -e "\ny\n123456\n123456\ny\ny\ny\ny\n"|/usr/local/mysql/bin/mysql_secure_installation &>/dev/null

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值