zoukankan      html  css  js  c++  java
  • (转) centos7下创建mysql5.6多实例

    原文:http://blog.csdn.net/a1010256340/article/details/77483504

    一、mysql安装目录说明
    mysql5.6以二进制安装包安装在/data/mysql56下
    数据目录为/data/mysql56/data下
    配置文件为/etc/my.cnf下

    二、多实例目录说明
    /mysql-instance
             |-- 3308
                      |-- data  #3308实例数据目录
             |-- 3309
                      |-- data  #3309实例数据目录

     
    1
    2
    mkdir -p /mysql-instance/3308/data
    mkdir -p /mysql-instance/3309/data

                      
    三、复制配置文件到实例目录下

     
    1
    2
    > cp /data/mysql56/support-files/my-default.cnf /mysql-instance/3308/my.cnf
    > cp /data/mysql56/support-files/my-default.cnf /mysql-instance/3309/my.cnf


    四、修改配置文件

     
    1
    2
    > vi /mysql-instance/3308/my.cnf
    > vi /mysql-instance/3309/my.cnf
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    [client]
    port = 3308
    socket = /mysql-instance/3308/mysql.sock
    [mysql]
    no-auto-rehash
    [mysqld]
    user = mysql
    port = 3308
    socket = /mysql-instance/3308/mysql.sock
    basedir = /data/mysql56
    datadir = /mysql-instance/3308/data
    pid-file = /mysql-instance/3308/mysql.pid
    relay-log = /mysql-instance/3308/relay-bin
    relay-log-info-file = /mysql-instance/3308/relay-log.info
    server-id = 12
    [mysqld_safe]
    log-error = /mysql-instance/3308/mysql.err
    pid-file = /mysql-instance/3308/mysql.pid

    3309的配置同上,只需把3308的地方换成3309

    五、创建mysql多实例启动文件

     
    1
    2
    > vi /mysql-instance/3308/mysql
    > vi /mysql-instance/3309/mysql
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    #!/bin/sh
    port=3308
    mysql_user="root"
    #请填写自已数据库密码
    mysql_pwd="123456"
    cmd_path="/data/mysql56/bin"
    mysql_sock="/mysql-instance/${port}/mysql.sock"
     
    mysql_start() {
        if [ ! -e "$mysql_sock" ];then
            printf "mysql start ... "
            /bin/sh ${cmd_path}/mysqld_safe --defaults-file=/mysql-instance/${port}/my.cnf 2>&1 > /dev/null &
        else
            printf "mysql is running ... "
            exit
        fi
    }
     
    mysql_stop() {
        if [ ! -e "$mysql_sock" ];then
            printf "mysql is stopped ... "
            exit
        else
            printf "mysql stop ... "
            ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S /mysql-instance/${port}/mysql.sock shutdown
        fi
    }
     
    mysql_restart() {
        printf "mysql restart ... "
        mysql_stop
        sleep 2
        mysql_start
    }
     
    case $1 in
        start) mysql_start ;;
        stop) mysql_stop ;;
        restart) mysql_restart ;;
    *)
    printf "usage: /data/${port}/mysql {start|stop|restart} "
    esac

     
    六、授权mysql用户目录权限

     
    1
    2
    3
    chown -R mysql.mysql /mysql-instance
    chmod 700 /mysql-instance/3308/mysql
    chmod 700 /mysql-instance/3309/mysql

     
    七、初始化mysql多实例数据库文件

     
    1
    2
    3
    > cd /daa/mysql56/scripts
    > ./mysql_install_db --basedir=/data/mysql56 --datadir=/mysql-instance/3308/data --user=mysql
    > ./mysql_install_db --basedir=/data/mysql56 --datadir=/mysql-instance/3309/data --user=mysql

     
    八、启动mysql多实例

     
    1
    2
    3
    > /mysql-instance/3308/mysql start
    > /mysql-instance/3309/mysql start
    > netstat -lntup|grep 330


    九、登陆mysql实例

     
    1
    > mysql -uroot -p -S /mysql-instance/3308/mysql.sock
  • 相关阅读:
    应对需求变更的软件的设计——我的想法
    重温数据库访问——故事篇
    用接口实现事件的一种方法,只是玩玩。
    面向对象最重要的是“抽象”,三层最重要的也是“抽象”,没有抽象就不是真正的面向对象、三层。
    【视频】自然框架之分页控件的使用方法(一) PostBack方式的一般分页方式
    【自然框架 免费视频】资源角色的思路介绍(整理了一下以前帖子的目录,请刷新)
    自信。
    钢铁是怎样炼成的?千锤百炼
    Android 中文API (94) —— MediaController
    android中文api(80)——Gallery.LayoutParams
  • 原文地址:https://www.cnblogs.com/liujiacai/p/7532210.html
Copyright © 2011-2022 走看看