二进制安装MySQL
只在centos7.9上测试了安装mysql5.7版本,脚本只是个人学习之余爱好,有问题希望大佬帮忙指正和修改建议
#!/bin/bash #******************************************************************** #Author: HE-handsome #QQ: 2700565402 #Date: 2022-10-14 #FileName: binary-mysql.sh #email: [email protected] #URL: https://www.cnblogs.com/smlience #Description:路漫漫其修远兮,吾将上下而求索 #******************************************************************** . /etc/os-release version=5.7.36 URL=https://downloads.mysql.com/archives/get/p/23/file/mysql-${version}-linux-glibc2.12-x86_64.tar.gz DATA_DIR=/data/mysql install_mysql() { echo -e "\e[1;36m 安装依赖包 \e[0m" if [ $ID == "rocky" -o $ID == "centos" ];then yum -y install libaio numactl-libs ncurses-compat-libs else apt update &> /dev/null apt -y install libaio numactl-libs ncurses-compat-libs fi if id mysql &> /dev/null;then echo -e "\e[1;36m 用户已存在 \e[0m" else groupadd -g 336 -r mysql && useradd -g mysql -s /sbin/nologin -d /data/mysql -r -u 336 mysql echo -e "\e[1;36m MySQL用户创建完成 \e[0m" fi if [ -e mysql-${version}-linux-glibc2.12-x86_64.tar.gz ];then echo -e "\e[1;36m 文件已存在,准备安装... \e[0m" else echo -e "\e[1;36m 开始下载源文件... \e[0m" wget $URL fi echo -e "\e[1;36m 正在解压源文件... \e[0m" tar xf mysql-${version}-linux-glibc2.12-x86_64.tar.gz -C /usr/local/ ln -s /usr/local/mysql-${version}-linux-glibc2.12-x86_64/ /usr/local/mysql chown -R root.root /usr/local/mysql/ echo 'PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh . /etc/profile.d/mysql.sh cp /etc/my.cnf{,.bak} cat > /etc/my.cnf <<EOF [mysqld] datadir=$DATA_DIR skip_name_resolve=1 socket=/data/mysql/mysql.sock log-error=/data/mysql/mysql.log pid-file=/data/mysql/mysql.pid [client] socket=/data/mysql/mysql.sock EOF [ ! -d /data/mysql ] && mkdir -p /data/mysql mysqld --initialize-insecure --user=mysql --datadir=/data/mysql cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld chkconfig --add mysqld service mysqld start [ $? -eq 0 ] && echo -e "\e[1;36m 数据库启动成功 \e[0m" || { echo -e "\e[1;36m 数据库启动失败 \e[0m";exit; } echo -e "\e[1;5;35m 现在是空密码,需要自己修改密码 \e[0m" echo -e "\e[1;5;35m 修改密码命令mysqladmin -uroot password 新密码 \e[0m" exec bash } install_mysql