码迷,mamicode.com
首页 > 数据库 > 详细

Mariadb-10.2.25 多实例

时间:2020-01-04 14:37:30      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:base   user   art   erro   mys   run   tin   attr   stopped   

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 ‘s@3306@3307@‘ /mysql/3307/etc/my.cnf
sed -i ‘s@3306@3308@‘ /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/

Mariadb-10.2.25 多实例

标签:base   user   art   erro   mys   run   tin   attr   stopped   

原文地址:https://www.cnblogs.com/1994july/p/12148830.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!