zoukankan      html  css  js  c++  java
  • 二进制mariadb多实例

    实验环境:

    centos7.6 :IP: 192.168.99.110

    1、首先下载二进制的压缩包,解压到一个指定的目录/hx/下

    
    [root@centos7 hx]#tar xf mariadb-10.2.23-linux-x86_64.tar.gz 
    [root@centos7 hx]#ls
    mariadb-10.2.23-linux-x86_64  mariadb-10.2.23-linux-x86_64.tar.gz  mysqld
    [root@centos7 hx]#mv mariadb-10.2.23-linux-x86_64 mysql

     2、在/usr/local/mysql/目录内新建多实例数据库的几个目录:这里3个实例的端口号为:3344,3355,3366

    [root@centos7 local]#mkdir -p ./mysql/{3344,3355,3366}/{etc,bin,log,socket,data,pid}
    3、先创建一个系统用户mysql,然后使用二进制目录里的脚本生成各自的数据目录
    [root@centos7 hx]#useradd -r -s /sbin/nolgoin -d /data/mysql  mysql  
    [root@centos7 hx]#getent passwd mysql 
    mysql:x:997:995::/data/mysql:/sbin/nolgoin

     报错:提示缺少一个依赖的库文件,我们使用yum安装一下这个libaio

    [root@centos7 hx]#/hx/mysql/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/3344/data/  #第一个实例:指定用户和生成数据库的目录
    Installing MariaDB/MySQL system tables in '/usr/local/mysql/3344/data/' ...
    OK   #有提示ok就说明成功了,也可以到/data/目录看一下
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system
    [root@centos7 hx]#/hx/mysql/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/3344/data/   #第二个实例
    Installing MariaDB/MySQL system tables in '/usr/local/mysql/3344/data/' ...
    OK 
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system
    [root@centos7 hx]#/hx/mysql/scripts/mysql_install_db --user=mysql --datadir=/usr/local/mysql/3344/data/  #第三个实例
    Installing MariaDB/MySQL system tables in '/usr/local/mysql/3344/data/' ...
    OK 
    To start mysqld at boot time you have to copy
    support-files/mysql.server to the right place for your system

    4、拷贝/etc/my.cnf配置文件到3个实例下的etc目录

    cp /etc/my.cnf /usr/local/mysql/3344/etc/
    vim /usr/local/mysql/3344/etc/ #添加一下几行,修改完后再拷贝到其他几个实例的etc目录内

    5、准备个简单的启动脚本,修改相应的参数拷贝到实例的bin目录内,并赋予执行权限

    #!/bin/bash
    #chkconfig: 35 80 2
    port=3344
    mysql_user="root"    
    mysql_pwd="xu"       
    cmd_path="/hx/mysql/bin/"     #此处设置为二进制mariadb目录的路径
    mysql_basedir="/usr/local/mysql/"   #设置三个实例的路径
    mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"    #指定socket文件路径
    function_start_mysql()
    {
        if [ ! -e "$mysql_sock" ];then
          printf "Starting MySQL...
    "
          ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf  &> /dev/null  &
        else
          printf "MySQL is running...
    "
          exit
        fi
    }
    function_stop_mysql()
           printf "MySQL is stopped...
    "
           exit
        else
           printf "Stoping MySQL...
    "
           ${cmd_path}/mysqladmin -u ${mysql_user}  -S ${mysql_sock} shutdown
       fi
    }
    function_restart_mysql()
    {
        printf "Restarting MySQL...
    "
        function_stop_mysql
        sleep 2
        function_start_mysql
    }
    case $1 in
    start)
        function_start_mysql
    ;;
    stop)
        function_stop_mysql
    ;;
    restart)
        function_restart_mysql
    ;;
    *)
        printf "Usage: ${mysql_basedir}/${port}/bin/mysqld {start|stop|restart}
    "
    esac

     6、最后设置一下权限:二进制目录和mysql多实例的目录属主和数组都设置为mysql

    通过脚本启动数据库,然后查看端口,3344,3355,3366三个实例都已经启动

    [root@centos7 3344]#ss -ntl 
    State       Recv-Q Send-Q         Local Address:Port                        Peer Address:Port              
    LISTEN      0      128                        *:22                                     *:*                  
    LISTEN      0      100                127.0.0.1:25                                     *:*                  
    LISTEN      0      80                        :::3344    ###                           :::*                  
    LISTEN      0      128                       :::22                                    :::*                  
    LISTEN      0      100                      ::1:25                                    :::*                  
    LISTEN      0      80                        :::3355    ###                           :::*                  
    LISTEN      0      80                        :::3366    ###                           :::*                  

    可以把二进制目录下的bin目录加入环境变量里,然后直接使用mysql -S 。 登录数据库时需要加 -S 指定socket文件进行登录,

  • 相关阅读:
    nodejs 的序列化与反序列化
    Visual Studio 监视与快速监视即时窗口没有智能提示
    mysql 备份数据语句
    mysql 导入sql 2006
    MySql.Data.MySqlClient.MySqlException (0x80004005): Unable to connect to any of the specified MySQL hosts.
    怎么查看mysql的安装目录
    【支付宝】退款接口 报 “缺少签名参数”
    【支付宝】"验签出错,sign值与sign_type参数指定的签名类型不一致:sign_type参数值为RSA,您实际用的签名类型可能是RSA2"
    【支付宝】支付 系统繁忙,请稍后再试(ALIN10146)
    php插入日志到数据库,对象转json
  • 原文地址:https://www.cnblogs.com/fengdejiyixx/p/11142955.html
Copyright © 2011-2022 走看看