Mariadb-10.2.25 多实例

Mariadb-10.2.25 多实例

定义目录

mkdir -p /mysql/{3306,3307,3308}/{bin,data,etc,log,pid,socket}

生成数据库文件

/app/mysql/scripts/mysql_install_db --datadir=/mysql/3306/data --user mysql
/app/mysql/scripts/mysql_install_db --datadir=/mysql/3307/data --user mysql
/app/mysql/scripts/mysql_install_db --datadir=/mysql/3308/data --user mysql

权限设置

chmod -R mysq.mysql /mysql

配置文件

cp mariadb-10.2.25/support-files/my-huge.cnf /mysql/3306/etc/my.cnf
vim /mysql/3306/etc/my.cnf

[mysqld]
datadir         = /mysql/3306/data
port            = 3306
socket          = /mysql/3306/socket/mysql.sock

[client]
port            = 3306
socket          = /mysql/3306/socket/mysql.sock

[mysqld_safe]
log-error=/mysql/3306/log/mariadb.log
pid-file=/mysql/3306/pid/mariadb.pid


cp /mysql/3306/etc/my.cnf /mysql/3307/etc/my.cnf
cp /mysql/3306/etc/my.cnf /mysql/3308/etc/my.cnf

sed -i ‘@‘ /mysql/3307/etc/my.cnf
sed -i ‘@‘ /mysql/3308/etc/my.cnf

启动脚本

#!/bin/bash

port=3306
mysql_user="root"
mysql_pwd="centos"
cmd_path="/app/mysql/bin"
mysql_basedir="/mysql"
mysql_sock="${mysql_basedir}/${port}/socket/mysql.sock"

function_start_mysql()
{
    if [ ! -e "$mysql_sock" ];then
      printf "Starting MySQL...\n"
      ${cmd_path}/mysqld_safe --defaults-file=${mysql_basedir}/${port}/etc/my.cnf  &> /dev/null  &
    else
      printf "MySQL is running...\n"
      exit
    fi
}


function_stop_mysql()
{
    if [ ! -e "$mysql_sock" ];then
       printf "MySQL is stopped...\n"
       exit
    else
       printf "Stoping MySQL...\n"
       ${cmd_path}/mysqladmin -u ${mysql_user} -p${mysql_pwd} -S ${mysql_sock} shutdown
   fi
}


function_restart_mysql()
{
    printf "Restarting MySQL...\n"
    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}\n"
esac

分别存放在 /mysql/{3306,3307,3308}/bin/mysqld,对应端口,添加执行权限

启动

/mysql/3306/bin/mysqld start
/mysql/3307/bin/mysqld start
/mysql/3308/bin/mysqld start

修改密码

mysqladmin -S /mysql/3306/socket/mysql.sock password centos
mysqladmin -S /mysql/3307/socket/mysql.sock password centos
mysqladmin -S /mysql/3308/socket/mysql.sock password centos

停止服务

/mysql/3306/bin/mysqld stop
/mysql/3307/bin/mysqld stop
/mysql/3308/bin/mysqld stop来源:http://www.1994july.club/

相关推荐