首页 > 数据库 > MySQL > 正文

mysql使用mysqld_multi部署单机多实例的方法教程

2024-07-24 12:50:34
字体:
来源:转载
供稿:网友

前言

大家应该都有所体会,随着硬件层面的发展,linux系统多核已经是普通趋势,而mysql是单进程多线程,所以先天上对多进程的利用不是很高,虽然5.6版本已经在这方面改进很多,但是也没有达到100%,所以为了充分的利用系统资源,mysql有自己的补充,那就是可以部署多实例,一个实例一个端口。

mysqld_multi设计用于管理在同一台机器上运行的多个mysqld进程,这些进程使用不同的socket文件并监听在不同的端口上。mysqld_multi可以批量启动、关闭、或者报告这些mysqld进程的状态。

下面话不多说了,来一起看看详细的介绍吧。

一、mysql编译安装:

cd /usr/local/srcwget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gzmv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysqlcd /usr/local/mysqluseradd mysqlmkdir -p /data/mysqlchown -R mysql:mysql /data/mysql./scripts/mysql_install_db --user=mysql --datadir=/data/mysqlcp support-files/my-default.cnf /etc/my.cnfcp support-files/mysql.server /etc/init.d/mysqld

二、准备第一个多实例3307

2.1 创建目录:

mkdir /usr/local/mysql3307chown -R mysql.mysql /usr/local/mysql3307/mkdir -p /data/mysql3307chown -R mysql.mysql /data/mysql3307mkdir -p /home/data/mysql3307/binlogchown -R mysql.mysql /home/data/mysql3307

2.2 配置文件

[root@zhdya01 ~]# vim /etc/my.cnf# For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the# *** default location during install, and will be replaced if you# *** upgrade to a newer version of MySQL.[mysqld_multi]mysqld = /usr/local/mysql/bin/mysqld_safemysqladmin =/usr/local/mysql/bin/mysqladminlog =/var/log/mysqld_multi.log[mysqld1]socket = /usr/local/mysql3307/mysql.sockport = 3307pid-file = /usr/local/mysql3307/mysql.piddatadir = /data/mysql3307log_bin=/home/data/mysql3307/binlogserver-id = 1innodb_buffer_pool_size = 128Minnodb_flush_log_at_trx_commit = 0

2.3 初始化数据库

/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3307

三、准备第二个多实例3308

3.1 创建目录:

mkdir /usr/local/mysql3308chown -R mysql.mysql /usr/local/mysql3308/mkdir -p /data/mysql3308chown -R mysql.mysql /data/mysql3308mkdir -p /home/data/mysql3308/binlogchown -R mysql.mysql /home/data/mysql3308

3.2 配置文件

[root@zhdya01 ~]# vim /etc/my.cnf# For advice on how to change settings please see# http://dev.mysql.com/doc/refman/5.6/en/server-configuration-defaults.html# *** DO NOT EDIT THIS FILE. It's a template which will be copied to the# *** default location during install, and will be replaced if you# *** upgrade to a newer version of MySQL.[mysqld_multi]mysqld = /usr/local/mysql/bin/mysqld_safemysqladmin =/usr/local/mysql/bin/mysqladminlog =/var/log/mysqld_multi.log[mysqld1]socket = /usr/local/mysql3307/mysql.sockport = 3307pid-file = /usr/local/mysql3307/mysql.piddatadir = /data/mysql3307log_bin=/home/data/mysql3307/binlogserver-id = 1innodb_buffer_pool_size = 128Minnodb_flush_log_at_trx_commit = 0[mysqld2]socket = /usr/local/mysql3308/mysql.sockport = 3308pid-file = /usr/local/mysql3308/mysql.piddatadir = /data/mysql3308log_bin=/home/data/mysql3308/binlogserver-id = 2innodb_buffer_pool_size = 128Minnodb_flush_log_at_trx_commit = 0
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表