前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >mysql利用mysqld_multi部署单机多实例

mysql利用mysqld_multi部署单机多实例

作者头像
老七Linux
发布2018-05-31 12:42:28
8290
发布2018-05-31 12:42:28
举报

近期博客更新不及时,是因为工作有了大的变动,今天分享个工作中遇到的一个小问题。

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

一、mysql编译安装:
代码语言:javascript
复制
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 创建目录:
代码语言:javascript
复制
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 配置文件
代码语言:javascript
复制
[[email protected] ~]# 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 初始化数据库
代码语言:javascript
复制
/usr/local/mysql/scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql --datadir=/data/mysql3307
三、准备第二个多实例3308
3.1 创建目录:
代码语言:javascript
复制
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 配置文件
代码语言:javascript
复制
[[email protected] ~]# 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 初始化数据库
代码语言:javascript
复制
/usr/local/mysql/scripts/mysql_install_db --user=mysql  --basedir=/usr/local/mysql --datadir=/data/mysql3308
四、启动多实例
代码语言:javascript
复制
/etc/init.d/mysqld start

mysqld_multi --defaults-extra-file=/etc/my.cnf start 1,2

[[email protected] 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  
五、查看启动状态
代码语言:javascript
复制
[[email protected] 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
六、停止多实例
代码语言:javascript
复制
[[email protected] bin]# mysqld_multi --defaults-extra-file=/etc/my.cnf stop 1,2

[[email protected] 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实例
代码语言:javascript
复制
[[email protected] 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> 
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2018/01/13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、mysql编译安装:
  • 二、准备第一个多实例3307
    • 2.1 创建目录:
      • 2.2 配置文件
        • 2.3 初始化数据库
        • 三、准备第二个多实例3308
          • 3.1 创建目录:
            • 3.2 配置文件
              • 3.3 初始化数据库
              • 四、启动多实例
              • 五、查看启动状态
              • 六、停止多实例
              • 七、各自登录mysql实例
              相关产品与服务
              云数据库 SQL Server
              腾讯云数据库 SQL Server (TencentDB for SQL Server)是业界最常用的商用数据库之一,对基于 Windows 架构的应用程序具有完美的支持。TencentDB for SQL Server 拥有微软正版授权,可持续为用户提供最新的功能,避免未授权使用软件的风险。具有即开即用、稳定可靠、安全运行、弹性扩缩等特点。
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档