shell脚本方式安装mysql

ps:本文采用5.7.24-ce版本,软件可以云清华源下载,上传到:/data/soft

#!/bin/bash
###1.初始化环境
systemctl stop firewalld.service
systemctl disable firewalld.service
sed -i ‘s#SELINUX=enforcing#SELINUX=disabled#g’ /etc/sysconfig/selinux
setenforce 0
###2.定义变量
hostnamectl set-hostname master
ip=$(ifconfig | awk 'NR==2{print KaTeX parse error: Expected 'EOF', got '}' at position 2: 2}̲') Hostname=(hostname)

3.mysql初始化

####3.1安装包路径,上传安装包
mkdir -p /data/soft && mkdir /application
yum install -y lrzsz
####3.2解压软件到配置文件路径
cd /data/soft
tar xf mysql-5.7.26-linux-glibc2.12-x86_64.tar.gz
mv mysql-5.7.26-linux-glibc2.12-x86_64 /application/mysql
####3.3设置环境变量
echo export PATH=/application/mysql/bin/:$PATH >>/etc/profile
source /etc/profile && mysql -V
####3.4安装mysql依赖包
yum remove mariadb-libs* -y && yum install -y libaio-devel
####3.5创建用户,授权
useradd -s /sbin/nologin mysql
mkdir /data/mysql/data -p && chown -R mysql. /data/mysql
chown -R mysql. /application
####3.6创建数据目录,并修改权限
####3.7初始化环境
\rm -rf /data/mysql/data/*
mysqld --initialize-insecure --user=mysql --basedir=/application/mysql --datadir=/data/mysql/data

####4.配置mysql.conf文件
cat >/etc/my.cnf< [mysqld]
user=mysql
basedir=/application/mysql
datadir=/data/mysql/data
socket=/tmp/mysql.sock
#定义日志写入方式
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
#binlog日志文件配置
server_id=6
log_bin=/data/mysql/mysql-bi
binlog_format=row
#二进制度自动清理
expire_logs_days=15
port=3306
#开启事物提交机制
autocommit=0
#开关慢日志
slow_query_log_file=/data/mysql/slow.log
long_query_time=0.5
log_queries_not_using_indexes
innodb_print_all_deadlocks = 1
[mysql]
socket=/tmp/mysql.sock
EOF

####4.1sys启动数据库
cp /application/mysql/support-files/mysql.server /etc/init.d/mysqld
/etc/init.d/mysqld restart

你可能感兴趣的:(mysql)