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

基于mysqld_multi实现MySQL 5.7.24多实例多进程配置

时间:2019-10-11 12:24:06      阅读:93      评论:0      收藏:0      [点我收藏+]

标签:set   isa   defaults   lock   password   star   启动   配置文件   link   

基于mysqld_multi实现MySQL 5.7.24多实例多进程配置

准备一台主机192.168.200.10

首先所有主机关闭防火墙与selinux

[root@localhost ~]# iptables -F

[root@localhost ~]# systemctl stop firewalld

[root@localhost ~]# systemctl disable firewalld

 

[root@localhost ~]# setenforce 0

[root@localhost ~]# sed -i ‘/SELINUX/ s/enforcing/disabled/g‘ /etc/sysconfig/selinux

一、创建并初始化数据目录

几个实例要分开运行,必然要把数据库文件放到不同目录中,所以第一步是要建立各个实例的数据目录,这里假设我们要运行三个实例,端口分别是3306,3307,3308,为了方便维护,我们把数据文件夹也按照端口号来命名:

[root@localhost ~]# mkdir -p /data/mysql/{3306,3307,3308}

[root@localhost ~]# chown mysql:mysql /data/mysql/{3306,3307,3308}

[root@localhost ~]# ls -ld /data/mysql/{3306,3307,3308}

drwxr-xr-x 2 mysql mysql 6 12月 7 16:37 /data/mysql/3306

drwxr-xr-x 2 mysql mysql 6 12月 7 16:37 /data/mysql/3307

drwxr-xr-x 2 mysql mysql 6 12月 7 16:37 /data/mysql/3308

 

二、通过配置文件指定并初始化数据目录

[root@localhost ~]# cp /etc/my.cnf /data/mysql/3308.cnf

[root@localhost ~]# vim /data/mysql/3308.cnf

[mysqld]

port=3308

datadir=/data/mysql/3308/

socket=/tmp/mysql3308.sock

symbolic-links=0

 

[mysqld_safe]

log-error=/data/mysql/3308.log

pid-file=/usr/local/mysql/data/3308.pid

 

[client]

port=3308

socket=/tmp/mysql3308.sock

 

[root@localhost ~]# mysqld --defaults-file=/data/mysql/3308.cnf --initialize-insecure --user=mysql

[root@localhost ~]# vim /data/mysql/3306.cnf

[mysqld]

port=3306

datadir=/data/mysql/3306/

socket=/tmp/mysql3306.sock

symbolic-links=0

 

[mysqld_safe]

log-error=/data/mysql/3306.log

pid-file=/usr/local/mysql/data/3306.pid

 

[client]

port=3306

socket=/tmp/mysql3306.sock

[root@localhost ~]# vim /data/mysql/3307.cnf

[mysqld]

port=3307

datadir=/data/mysql/3307/

socket=/tmp/mysql3307.sock

symbolic-links=0

 

[mysqld_safe]

log-error=/data/mysql/3307.log

pid-file=/usr/local/mysql/data/3307.pid

 

[client]

port=3307

socket=/tmp/mysql3307.sock

[root@localhost ~]# mysqld --defaults-file=/data/mysql/3307.cnf --initialize-insecure --user=mysql

[root@localhost ~]# mysqld --defaults-file=/data/mysql/3306.cnf --initialize-insecure --user=mysql

 

二、配置my.cnf文件集中管理多个实例

[root@localhost ~]# cp /etc/my.cnf /etc/my.cnf.bak

[root@localhost ~]# vim /etc/my.cnf

[mysqld_multi]

mysqld=/usr/local/mysql/bin/mysqld_safe

mysqladmin=/usr/local/mysql/bin/mysqladmin

 

[mysqld1]

port=3306

socket=/tmp/mysql3306.sock

datadir=/data/mysql/3306/

skip-external-locking

log-bin=/data/mysql/3306/mysql-bin

server-id=3306

user=mysql

 

[mysqld2]

port=3307

socket=/tmp/mysql3307.sock

datadir=/data/mysql/3307/

skip-external-locking

log-bin=/data/mysql/3307/mysql-bin

server-id=3307

user=mysql

 

[mysqld3]

port=3308

socket=/tmp/mysql3308.sock

datadir=/data/mysql/3308/

skip-external-locking

log-bin=/data/mysql/3308/mysql-bin

server-id=3308

user=mysql

 

[mysql]

no-auto-rehash

 

mysqld_multi的配置文件和一般MySQL配置不同,没有[mysqld]段,取而代之的是[mysqld1]、[mysqld2]等配置段,每个配置段代表一个MySQL实例。

三、管理多个MySQL实例

1,启动多个MySQL实例

启动多个实例时需要一个启动脚本,这个脚本一般在/usr/local/mysql/support-files目录下的mysqld_multi.server文件

[root@localhost ~]# cp /usr/local/mysql/support-files/mysqld_multi.server /etc/init.d/mysqld_multi

 

启动多个MySQL实例

[root@localhost ~]# /etc/init.d/mysqld_multi start 1-3

 

启动三个MySQL实例,注意这里的数字和my.cnf中的[mysqldN]对应,1-3就是启动[mysqld1]、[mysqld2]、[mysqld3]配置段的MySQL实例。

 

[root@localhost ~]# netstat -lnpt | grep -E "3306|3307|3308"

tcp6 0 0 :::3306 :::* LISTEN 2744/mysqld

tcp6 0 0 :::3307 :::* LISTEN 65502/mysqld

tcp6 0 0 :::3308 :::* LISTEN 65499/mysqld

四、root账户管理

前面初始化数据库时用的是--initialize-insecure参数,所以我们初始化的数据库,root账户是没有密码的,要先改密码为123456:

mysqladmin -uroot password ‘123456‘ -S /tmp/mysql3306.sock

mysqladmin -uroot password ‘123456‘ -S /tmp/mysql3307.sock

mysqladmin -uroot password ‘123456‘ -S /tmp/mysql3308.sock

五、连接mysql多实例:

[root@localhost ~]# mysql -u root -p123456 -S /tmp/mysql3306.sock

[root@localhost ~]# mysql -u root -p123456 -S /tmp/mysql3307.sock

[root@localhost ~]# mysql -u root -p123456 -S /tmp/mysql3308.sock

 

 

 

基于mysqld_multi实现MySQL 5.7.24多实例多进程配置

标签:set   isa   defaults   lock   password   star   启动   配置文件   link   

原文地址:https://www.cnblogs.com/liyurui/p/11653363.html

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