• mysql启动脚本


    一台服务器上安装多个MySQL实例之后,实例的启动关闭不能再用service mysqld start/stop/restart命令,所以编写如下脚本用于启动关闭对应端口的实例。

    这个脚本适用于多实例版本,一台服务器上安装多个实例,不同端口,其中my.cnf文件放在mysql的databasedir目录下面:

    例如开启3310端口的mysql:./mysql_start start 3310

    #cat mysql_start

    #!/bin/bash
    start_mode=$1
    mysql_port=$2
    function_start_mysql()
    {
    stat=$(netstat -antlp|grep ${mysql_port}|grep LISTEN|grep mysql)
    if [ -z "$stat" ]; then
    printf "Starting MySQL...
    "
    /usr/local/mysql/bin/mysqld_safe --defaults-file=/data/mysql${mysql_port}/my.cnf 2>&1 >/dev/null &
    else
    printf "MySQL Started
    "
    fi
    }
    function_stop_mysql()
    {
    stat=$(netstat -antlp|grep ${mysql_port}|grep LISTEN|grep mysql)
    if [ -n "$stat" ]; then
    printf "Stoping MySQL...
    "
    /usr/local/mysql/bin/mysqladmin -S /data/mysql${mysql_port}/mysql.sock shutdown
    else
    printf "MySQL Stoped
    "
    fi
    }
    function_restart_mysql()
    {
    printf "Restarting MySQL...
    "
    function_stop_mysql
    function_start_mysql
    }
    function_kill_mysql()
    {
    kill -9 $(ps -ef|grep ${mysql_port}|grep bin/mysqld_safe|awk '{print $2}')
    kill -9 $(ps -ef|grep ${mysql_port}|grep bin/mysqld|awk '{print $2}')
    }
    case $1 in 
    start)
    function_start_mysql;;
    stop)
    function_stop_mysql;;
    restart)
    function_restart_mysql;;
    kill)
    function_kill_mysql;;
    *)
    echo "Usage: /data/mysql${mysql_port}/mysqld {start|stop|restart|kill}";;
    esac
  • 相关阅读:
    安装sublime text2 for ubuntu
    ruby中Regexp用法
    rvm is not a function的解决方法
    解决启动mongod 时,出现addr already in use错误
    rails中常用的插件
    在数据库中存储层次数据
    Formtastic: Forms Made Crazy Easy for Rails Developers
    rails安全性
    Rails 增加一个模型(model)
    RPC框架实现思路浅析
  • 原文地址:https://www.cnblogs.com/zx3212/p/8268148.html
Copyright © 2020-2023  润新知