mysql主从脚本--主

标题mysql主从脚本–主

#!/bin/bashecho "关闭防火墙" systemctl stop firewalld.service setenforce 0#判断防火墙是否关闭 if [ $? -eq 0 ]; then echo "防火墙关闭成功" else echo "防火墙关闭失败" fi #查看mysql是否安装 rpm -qa | grep mariadb &> /dev/nullif [ $? -eq 0 ]; then echo "已安装mariadb" yum -y remove mariadb mariadb-libs-5.5.64-1.el7.x86_64 mariadb-server-5.5.64-1.el7.x86_64 mariadb-5.5.64-1.el7.x86_64 &> /dev/null if [ $? -eq 0 ]; then echo "已经删除数据库 安装数据库" yum -y install mariadb mariadb-server &> /dev/null fi else echo "没有安装数据库,正在安装数据库" # 安装数据库 yum -y install mariadb mariadb-server &> /dev/null #判断是否安装成功 if [ $? -eq 0 ]; then echo "安装成功" else echo "安装失败 重新安装" yum -y install mariadb mariadb-server &> /dev/null fi fi #修改mysql的配置文件,启动mysql echo "编写my.cnf文件" sed -i '10aserver-id=1' /etc/my.cnf sed -i '11alog-bin=mysql-bin' /etc/my.cnf sed -i '12arelay-log=mysql-relay' /etc/my.cnf systemctl start mariadb#判断是否启动成功 if [ $? -eq 0 ]; then echo "数据库启动成功" else echo "数据库启动失败 请检查配置文件文件" fi#给从授权 echo "开始授权" mysql -e "grant all on *.* to 'tom'@'%'identified by '123456'; " if [ $? -eq 0 ]; then echo "授权成功" else echo "授权失败" fiecho "刷新数据库权限" mysql -e "flush privileges; "echo "查看日志" mysql -e "show master status; " if [ $? -eq 0 ]; then echo "日志已经有了" else echo "日志错误 查看配置文件" fi

    推荐阅读