mysql使用mysqld_multi部署单机多实例的方法教程
作者:zhdya 时间:2024-01-15 12:26:01
前言
大家应该都有所体会,随着硬件层面的发展,linux系统多核已经是普通趋势,而mysql是单进程多线程,所以先天上对多进程的利用不是很高,虽然5.6版本已经在这方面改进很多,但是也没有达到100%,所以为了充分的利用系统资源,mysql有自己的补充,那就是可以部署多实例,一个实例一个端口。
mysqld_multi设计用于管理在同一台机器上运行的多个mysqld进程,这些进程使用不同的socket文件并监听在不同的端口上。mysqld_multi可以批量启动、关闭、或者报告这些mysqld进程的状态。
下面话不多说了,来一起看看详细的介绍吧。
一、mysql编译安装:
cd /usr/local/src
wget 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.gz
mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql
cd /usr/local/mysql
useradd mysql
mkdir -p /data/mysql
chown -R mysql:mysql /data/mysql
./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
cp support-files/my-default.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
二、准备第一个多实例3307
2.1 创建目录:
mkdir /usr/local/mysql3307
chown -R mysql.mysql /usr/local/mysql3307/
mkdir -p /data/mysql3307
chown -R mysql.mysql /data/mysql3307
mkdir -p /home/data/mysql3307/binlog
chown -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_safe
mysqladmin =/usr/local/mysql/bin/mysqladmin
log =/var/log/mysqld_multi.log
[mysqld1]
socket = /usr/local/mysql3307/mysql.sock
port = 3307
pid-file = /usr/local/mysql3307/mysql.pid
datadir = /data/mysql3307
log_bin=/home/data/mysql3307/binlog
server-id = 1
innodb_buffer_pool_size = 128M
innodb_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/mysql3308
chown -R mysql.mysql /usr/local/mysql3308/
mkdir -p /data/mysql3308
chown -R mysql.mysql /data/mysql3308
mkdir -p /home/data/mysql3308/binlog
chown -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_safe
mysqladmin =/usr/local/mysql/bin/mysqladmin
log =/var/log/mysqld_multi.log
[mysqld1]
socket = /usr/local/mysql3307/mysql.sock
port = 3307
pid-file = /usr/local/mysql3307/mysql.pid
datadir = /data/mysql3307
log_bin=/home/data/mysql3307/binlog
server-id = 1
innodb_buffer_pool_size = 128M
innodb_flush_log_at_trx_commit = 0
[mysqld2]
socket = /usr/local/mysql3308/mysql.sock
port = 3308
pid-file = /usr/local/mysql3308/mysql.pid
datadir = /data/mysql3308
log_bin=/home/data/mysql3308/binlog
server-id = 2
innodb_buffer_pool_size = 128M
innodb_flush_log_at_trx_commit = 0
3.3 初始化数据库
/usr/local/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql3308
四、启动多实例
/etc/init.d/mysqld start
mysqld_multi --defaults-extra-file=/etc/my.cnf start 1,2
[root@zhdya01 bin]# !net
netstat -lntp -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1241/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2087/master
tcp6 0 0 :::3306 :::* LISTEN 4406/mysqld
tcp6 0 0 :::3307 :::* LISTEN 4197/mysqld
tcp6 0 0 :::3308 :::* LISTEN 3359/mysqld
tcp6 0 0 :::8080 :::* LISTEN 2222/java
tcp6 0 0 :::22 :::* LISTEN 1241/sshd
tcp6 0 0 ::1:25 :::* LISTEN 2087/master
五、查看启动状态
[root@zhdya01 bin]# mysqld_multi --defaults-extra-file=/etc/my.cnf report
Reporting MySQL servers
MySQL server from group: mysqld1 is running
MySQL server from group: mysqld2 is running
六、停止多实例
[root@zhdya01 bin]# mysqld_multi --defaults-extra-file=/etc/my.cnf stop 1,2
[root@zhdya01 bin]# mysqld_multi --defaults-extra-file=/etc/my.cnf report
Reporting MySQL servers
MySQL server from group: mysqld1 is not running
MySQL server from group: mysqld2 is not running
七、各自登录mysql实例
[root@zhdya01 bin]# mysql --socket=/usr/local/mysql3307/mysql.sock
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.35-log MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
来源:http://www.okay686.cn/943.html
标签:mysql,mysqld,multi,多实例
0
投稿
猜你喜欢
导航设计的流行趋势
2007-12-25 12:06:00
python内存动态分配过程详解
2023-10-02 14:58:46
python anaconda 安装 环境变量 升级 以及特殊库安装的方法
2022-11-05 01:56:24
IDEA版使用Java操作Redis数据库的方法
2024-01-19 22:15:34
django的模型类管理器——数据库操作的封装详解
2024-01-12 19:12:53
MYSQL使用正则表达式过滤数据
2024-01-13 05:33:25
Dreamweaver4探谜系列(2)
2010-05-13 12:08:00
Javascript typeof与instanceof的区别
2024-06-07 15:53:47
千篇一律的JS运算符讲解,一起来看看
2024-05-13 10:06:52
教你用scrapy框架爬取豆瓣读书Top250的书类信息
2022-11-04 12:48:23
Dojo Style Javascript 编程规范
2007-10-25 17:24:00
Python的函数的一些高阶特性
2022-06-04 15:06:28
python使用新浪微博api上传图片到微博示例
2021-10-13 02:15:06
解决selenium+Headless Chrome实现不弹出浏览器自动化登录的问题
2022-01-14 12:27:24
JavaScript实现全选取消效果
2023-08-27 16:26:42
Go整合captcha实现验证码功能
2024-04-26 17:29:43
Mysql逗号拼接字符串的关联查询以及统计问题
2024-01-28 12:15:03
“语法错误 (逗号) 在查询表达式id=20, 21”,怎么处理这个逗号?
2009-09-18 14:52:00
asp 简单分页代码
2011-03-11 10:53:00
前端框架之封装Vue第三方组件三个技巧
2023-07-02 16:37:03