数据库篇~基于mysql_multi的数据库多实例安装

数据库 mysqld_multi 多实例安装

之前的文章里面讲述了, 数据库 5.7数据库安装, 现在讲解下基于5.7数据库安装多实例问题.

步骤如下:

  1. 创建数据文件路径 并 授权
  2. 配置 my.cnf mysqld_multi模块, 配置多实例
  3. 初始化数据库 5.7
  4. 拷贝 mysqld_multi.server 到 /etc/init.d/mysqld_multi 并修改配置
  5. 启动服务
  6. 关闭服务
1. 创建数据文件路径 并 授权

默认安装根目录 /service/application/

mkdir -P {3307,3308,3309}

cd 3307 && mkdir -P {data,logs,tmp,etc}
cd 3308 && mkdir -P {data,logs,tmp,etc}
cd 3309 && mkdir -P {data,logs,tmp,etc}

chown -R mysql:mysql 3307
chown -R mysql:mysql 3308
chown -R mysql:mysql 3309

2.配置 my.cnf mysqld_multi模块, 配置多实例

默认安装目录 /service/application/mysql/etc

vim /service/application/mysql/etc/my.cnf 

#在配置文件里面进行添加 mysqld_multi 模块

[mysqld_multi]
mysqld=/service/application/mysql/bin/mysqld_safe
mysqladmin=/service/application/mysql/bin/mysqladmin
log=/service/application/mysql/logs/mysql_multi.log
user=hailong
password=123456

[mysqld1]
datadir=/service/application/3307/data
port=3307
server_id=3307
socket=/service/application/3307/tmp/mysql.sock
symbolic-links=0
character_set_server=utf8
pid-file=/service/application/3307/tmp/mysql7.pid

[mysqld2]
datadir=/service/application/3308/data
port=3308
server_id=3308
socket=/service/application/3308/tmp/mysql.sock
symbolic-links=0
character_set_server=utf8
pid-file=/service/application/3308/tmp/mysql8.pid

[mysqld3]
datadir=/service/application/3309/data
port=3309
server_id=3309
socket=/service/application/3309/tmp/mysql.sock
symbolic-links=0
character_set_server=utf8
pid-file=/service/application/3309/tmp/mysql9.pid

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES 

[mysql]
#character_set_server=utf8

3. 初始化数据库 5.7
#进行数据库初始化
#3309
/service/application/mysql/bin/mysqld --no-defaults --initialize --user=mysql --basedir=/service/application/mysql --datadir=/service/application/3309/data --explicit_defaults_for_timestamp
#3308
/service/application/mysql/bin/mysqld --no-defaults --initialize --user=mysql --basedir=/service/application/mysql --datadir=/service/application/3308/data --explicit_defaults_for_timestamp
#3307
/service/application/mysql/bin/mysqld --no-defaults --initialize --user=mysql --basedir=/service/application/mysql --datadir=/service/application/3307/data --explicit_defaults_for_timestamp
4. 拷贝 mysqld_multi.server/etc/init.d/mysqld_multi
cp /service/application/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi

#具体的代码如下
#!/bin/sh
#
# A simple startup script for mysqld_multi by Tim Smith and Jani Tolonen.
# This script assumes that my.cnf file exists either in /etc/my.cnf or
# /root/.my.cnf and has groups [mysqld_multi] and [mysqldN]. See the
# mysqld_multi documentation for detailed instructions.
#
# This script can be used as /etc/init.d/mysql.server
#
# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.
#
# Version 1.0
#

basedir=/service/application/mysql
bindir=/service/application/mysql/bin
conf=/service/application/mysql/etc/my.cnf

if test -x $bindir/mysqld_multi
then
  mysqld_multi="$bindir/mysqld_multi";
else
  echo "Can't execute $bindir/mysqld_multi from dir $basedir";
  exit;
fi

case "$1" in
    'start' )
        "$mysqld_multi" --defaults-extra-file=$conf start $2
        ;;
    'stop' )
        "$mysqld_multi" --defaults-extra-file=$conf stop $2
        ;;
    'report' )
        "$mysqld_multi" --defaults-extra-file=$conf report $2
        ;;
    'restart' )
        "$mysqld_multi" --defaults-extra-file=$conf stop $2
        "$mysqld_multi" --defaults-extra-file=$conf start $2
        ;;
    *)
        echo "Usage: $0 {start|stop|report|restart}" >&2
        ;;
esac
5. 启动服务
/etc/init.d/mysqld_multi start
/etc/init.d/mysqld_multi report

#如果成功则显示如下结果
[root@oldboy ~]# /etc/init.d/mysqld_multi report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
MySQL server from group: mysqld3 is running
6. 关闭服务
#单独关闭服务
mysqladmin -uhailong -P 3308 -p shutdown -S '/service/application/3308/tmp/mysql.sock'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值