mysql多实例搭建
一)多实例安装
[root@mysqlmaster01 ~]# mkdir /data/mysql_data2
[root@mysqlmaster01 ~]# mkdir /data/mysql_data3
[root@mysqlmaster01 ~]# mkdir /data/mysql_data4
[root@mysqlmaster01 ~]# cp -rf /data/mysql_data/mysql/ /data/mysql_data2
[root@mysqlmaster01 ~]# cp -rf /data/mysql_data/mysql/ /data/mysql_data3
[root@mysqlmaster01 ~]# cp -rf /data/mysql_data/mysql/ /data/mysql_data4
[root@mysqlmaster01 ~]# chown -R mysql.mysql /data/mysql_data2
[root@mysqlmaster01 ~]# chown -R mysql.mysql /data/mysql_data3
[root@mysqlmaster01 ~]# chown -R mysql.mysql /data/mysql_data4
配置my.cnf参数
[root@mysqlmaster01 ~]# cat /etc/my.cnf
[client]
user=root
#password = 123456
socket = /tmp/mysql.sock
[mysqld_multi]
user=david
pass=Aa123456
(注意:以上2个用户名和密码,必须事先用root登录localhost,授权该用户拥有shutdown权限)
mysqld = /usr/local/mysql/bin/mysqld_safe
mysqladmin = /usr/local/mysql/bin/mysqladmin
log = /usr/local/mysql/multi.log
[mysqld1]
server-id = 11
datadir=/data/mysql_data1
socket=/tmp/mysql.sock1
port=3306
user=mysql
performance_schema=off
bind_address=10.2.11.226
skip_name_resolve=1
innodb_buffer_pool_size=32M
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 2
log_bin = bin.log
[mysqld2]
server-id = 12
datadir=/data/mysql_data2
socket=/tmp/mysql.sock3
port=3307
user=mysql
performance_schema=off
bind_address=10.2.11.226
skip_name_resolve=1
innodb_buffer_pool_size=32M
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 2
log_bin = bin.log
[mysqld3]
server-id = 13
datadir=/data/mysql_data3
socket=/tmp/mysql.sock3
port=3308
user=mysql
performance_schema=off
bind_address=10.2.11.226
skip_name_resolve=1
innodb_buffer_pool_size=32M
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 2
log_bin = bin.log
[mysqld4]
server-id = 14
datadir=/data/mysql_data4
socket=/tmp/mysql.sock4
port=3309
user=mysql
performance_schema=off
bind_address=10.2.11.226
skip_name_resolve=1
innodb_buffer_pool_size=32M
log_error = error.log
slow_query_log = 1
slow_query_log_file = slow.log
long_query_time = 2
log_bin = bin.log
[root@mysqlmaster01 ~]# mysqld_multi start 1
[root@mysqlmaster01 ~]# mysqld_multi start 2
[root@mysqlmaster01 ~]# mysqld_multi start 3
[root@mysqlmaster01 ~]# mysqld_multi start 4
查看:
[root@mysqlmaster01 mysql_data1]# ll
total 110628
-rw-r-----. 1 mysql mysql 56 Nov 23 13:30 auto.cnf
-rw-r-----. 1 mysql mysql 177 Nov 23 13:30 bin.000001
-rw-r-----. 1 mysql mysql 13 Nov 23 13:30 bin.index
-rw-r-----. 1 mysql mysql 9335 Nov 23 13:30 error.log
-rw-r-----. 1 mysql mysql 215 Nov 23 13:30 ib_buffer_pool
-rw-r-----. 1 mysql mysql 12582912 Nov 23 13:30 ibdata1
-rw-r-----. 1 mysql mysql 50331648 Nov 23 13:30 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 Nov 23 13:30 ib_logfile1
drwxr-x---. 2 root root 4096 Nov 23 13:29 mysql
-rw-r-----. 1 mysql mysql 185 Nov 23 13:30 slow.log
[root@mysqlmaster01 mysql_data2]# ll
total 122928
-rw-r-----. 1 mysql mysql 56 Nov 23 13:30 auto.cnf
-rw-r-----. 1 mysql mysql 154 Nov 23 13:30 bin.000001
-rw-r-----. 1 mysql mysql 13 Nov 23 13:30 bin.index
-rw-r-----. 1 mysql mysql 21180 Nov 23 13:30 error.log
-rw-r-----. 1 mysql mysql 12582912 Nov 23 13:30 ibdata1
-rw-r-----. 1 mysql mysql 50331648 Nov 23 13:30 ib_logfile0
-rw-r-----. 1 mysql mysql 50331648 Nov 23 13:30 ib_logfile1
-rw-r-----. 1 mysql mysql 12582912 Nov 23 13:30 ibtmp1
drwxr-x---. 2 mysql mysql 4096 Nov 23 11:52 mysql
-rw-r-----. 1 mysql mysql 5 Nov 23 13:30 mysqlmaster01.test.com.pid
-rw-r-----. 1 mysql mysql 185 Nov 23 13:30 slow.log
(其他的类似)
查看
[root@mysqlmaster01 mysql_data3]# ss -tunlp|grep 33*
tcp LISTEN 0 80 10.2.11.226:3306 *:* users:(("mysqld",8937,14))
tcp LISTEN 0 80 10.2.11.226:3307 *:* users:(("mysqld",10191,14))
tcp LISTEN 0 80 10.2.11.226:3308 *:* users:(("mysqld",10487,14))
tcp LISTEN 0 80 10.2.11.226:3309 *:* users:(("mysqld",9831,14))
客户端登录:
[root@mysqlmaster01 data]# mysql -u root -p -S /tmp/mysql.sock4
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.7.20-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>
问题1:
由于mysql目录中有一些其他引擎的,如.CSV或.ibd,通过cp直接拷贝到新的数据目录,不能直接使用。
例如需要开启某些特定的时候,这时候就会报该表不存在的错误
解决办法:
建议不要直接拷贝mysql目录,建议针对每个实例进行初始化一次,建议用方法二
第二种方法:每个实例的mysql数据库不一样
1)先建立4个数据目录,并授权mysql
[root@mysqlmaster01 ~]# mkdir /data/mysql_data1
[root@mysqlmaster01 ~]# mkdir /data/mysql_data2
[root@mysqlmaster01 ~]# mkdir /data/mysql_data3
[root@mysqlmaster01 ~]# mkdir /data/mysql_data4
[root@mysqlmaster01 ~]# chown -R mysql.mysql /data/mysql_data2
[root@mysqlmaster01 ~]# chown -R mysql.mysql /data/mysql_data2
[root@mysqlmaster01 ~]# chown -R mysql.mysql /data/mysql_data3
[root@mysqlmaster01 ~]# chown -R mysql.mysql /data/mysql_data4
[root@mysqlmaster01 data]# mysqld_multi start
Installing new database in /data/mysql_data1
2017-11-23T07:01:17.586587Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-23T07:01:20.262722Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-23T07:01:20.781961Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-23T07:01:20.906340Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 1c362b80-d01c-11e7-8b36-5254006fdb68.
2017-11-23T07:01:20.914259Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-11-23T07:01:20.914769Z 1 [Note] A temporary password is generated for root@localhost: NLRkTWz0*118
Installing new database in /data/mysql_data2
2017-11-23T07:01:27.118069Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-23T07:01:30.663893Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-23T07:01:31.268511Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-23T07:01:31.348118Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 226f7556-d01c-11e7-8cdf-5254006fdb68.
2017-11-23T07:01:31.359957Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-11-23T07:01:31.360777Z 1 [Note] A temporary password is generated for root@localhost: N1I+qXlfryrK
Installing new database in /data/mysql_data3
2017-11-23T07:01:37.639565Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-23T07:01:40.316276Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-23T07:01:40.829721Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-23T07:01:40.906120Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2821e4e8-d01c-11e7-99cc-5254006fdb68.
2017-11-23T07:01:40.910204Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-11-23T07:01:40.910899Z 1 [Note] A temporary password is generated for root@localhost: 0Ip4hLFb;s;m
Installing new database in /data/mysql_data4
2017-11-23T07:01:47.200346Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2017-11-23T07:01:50.377236Z 0 [Warning] InnoDB: New log files created, LSN=45790
2017-11-23T07:01:50.739399Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2017-11-23T07:01:50.814170Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 2e09bdfe-d01c-11e7-a8da-5254006fdb68.
2017-11-23T07:01:50.818480Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2017-11-23T07:01:50.819161Z 1 [Note] A temporary password is generated for root@localhost: rf.Kle8hlm8i
[root@mysqlmaster01 ~]# ss -tunlp|grep 33
tcp LISTEN 0 80 10.2.11.226:3306 *:* users:(("mysqld",17901,29))
tcp LISTEN 0 80 10.2.11.226:3307 *:* users:(("mysqld",17914,15))
tcp LISTEN 0 80 10.2.11.226:3308 *:* users:(("mysqld",17918,14))
tcp LISTEN 0 80 10.2.11.226:3309 *:* users:(("mysqld",17917,14))
客户端登录:
[root@mysqlmaster01 data]# mysql -u root -p -S /tmp/mysql.sock1
Enter password: NLRkTWz0*118
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.20-log
Copyright (c) 2000, 2017, 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> set password="Aa123456";
Query OK, 0 rows affected (0.04 sec)
mysql> exit
Bye
配置启动服务
[root@mysqlmaster01 data]# cd /usr/local/mysql
[root@mysqlmaster01 mysql]# cp support-files/mysqld_multi.server /etc/init.d/mysqld_multi
[root@mysqlmaster01 mysql]# chkconfig --add mysqld_multi
[root@mysqlmaster01 mysql]# chkconfig mysqld_multi on
[root@mysqlmaster01 mysql]# chkconfig --list|grep mysqld_multi
mysqld_multi 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@mysqlmaster01 ~]# /etc/init.d/mysqld_multi start
[root@mysqlmaster01 ~]# ss -tunlp|grep 33
[root@mysqlmaster01 ~]# ss -tunlp|grep 33
tcp LISTEN 0 80 10.2.11.226:3306 *:* users:(("mysqld",2066,34))
[root@mysqlmaster01 ~]# ss -tunlp|grep 33
tcp LISTEN 0 80 10.2.11.226:3306 *:* users:(("mysqld",2066,34))
tcp LISTEN 0 80 10.2.11.226:3307 *:* users:(("mysqld",2074,15))
tcp LISTEN 0 80 10.2.11.226:3308 *:* users:(("mysqld",2090,15))
tcp LISTEN 0 80 10.2.11.226:3309 *:* users:(("mysqld",2094,27))
[root@mysqlmaster01 ~]#
[root@mysqlmaster01 ~]#
[root@mysqlmaster01 ~]# /etc/init.d/mysqld_multi stop
[root@mysqlmaster01 ~]# ss -tunlp|grep 33
[root@mysqlmaster01 ~]#
解决办法:https://www.cnblogs.com/qizhelongdeyang/p/6292966.html
mysql多实例搭建的更多相关文章
- Mysql多实例搭建部署
[部署背景] 公司测试环境需求多个数据库实例,但是只分配一台MySQL机器,所以进行多实例部署. [部署搭建] 创建软件包路径 mkdir /data/soft/package /dat ...
- Mysql集群搭建(多实例、主从)
1 MySQL多实例 一 .MySQL多实例介绍 1.什么是MySQL多实例 MySQL多实例就是在一台机器上开启多个不同的服务端口(如:3306,3307,3308),运行多个MySQL服务进程,通 ...
- MySQL多实例,主从同步
由于背景原因,所做的主从同步还是要基于MySQL 5.1的版本,主从同步主要是一个数据库读写访问原来的数据库热度过大,需要做到使用从库对读分压. MySQL主从同步介绍 MySQL 支持单双向 ...
- mysql多实例(个人的情况,不是大众的)里面有配置好的脚本+主从复制
[root@DB-S ~]# ll /usr/local/|grep mysql lrwxrwxrwx. 1 root root 21 Jun 14 01:52 mysql -> /alidat ...
- MySQL多实例-精典故障案例
很久以前搭建过MySQL多实例,记得当时很顺利,呵呵!今天公司因为业务需要,我再一次搭建多实例.安装完MySQL后,初始化两个实例时,出现如下报错: 150915 1:10:36 [ERROR] C ...
- 如何在同一台机器上安装多个MySQL的实例
转自:'http://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的 ...
- mysql MHA架构搭建过程
[环境介绍] 系统环境:Red Hat Enterprise Linux 7 + 5.7.18 + MHA version 0.57 系统 IP 主机名 备注 版本 xx系统 192.168.142. ...
- 云服务器+tomcat+mysql+web项目搭建部署
云服务器+tomcat+mysql+web项目搭建部署 1.老样子,开头墨迹两句. 作为我的第二篇文章,有很多感慨,第一篇人气好低啊,有点小丧气,不过相信我还是经验少,分享的都是浅显的,所以大家可能不 ...
- 如何在同一台机器上安装多个MySQL的实例 转
https://www.cnblogs.com/shangzekai/p/4375271.html 最近由于工作的需要,需要在同一台机器上搭建两个MySQL的实例,(注:已经存在了一个3306的MyS ...
随机推荐
- 《基于Scyther的秘钥建立协议设计》-------摘抄整理
本篇论文额主要创新点: 利用Scyther软件,通过对一个不安全的秘钥建立协议逐步添加并验证安全属性,最终建立一个安全的秘钥建立协议. 通过形式化分析软件设计秘钥建立协议课可以提高协议设计效率,减 ...
- EtherNet/IP 协议应用层使用CIP协议&CIP协议中使用的TLS和DTLS(Network Infrastructure for EtherNet/IPTM: Introduction and Considerations)
- C语言字符串格式化输出
%ms:将字符串全部输出,如果字符串长度小于m,在左边用空格将输出宽度补齐为m: %.ns:如果n大于字符串长度,将字符串全部输出,否则,输出前n个字符: %m.ns:如果n不大于m,输出指定字符串的 ...
- 【Spring】源码浅析 - ResponseEntity.ok 转载
https://www.jianshu.com/p/1238bfb29ee1 ResponseEntity.ok具体源码
- Python 编码encode()、 解码decode()问题
乱码这种东西,时不时出现.本来开开心心想着我要学习啦,然后兴高采烈打开了比火星文还火星文的字符-- 没事,我可以搞定这堆鬼画符. 先来讲一下为什么有乱码这种东西的存在 故事是这样滴: 字符串是Pyth ...
- ZZNUOJ-2154:单身狗线下聚会【求N个数的最小公倍数,会超longlong,大数乘法,Java】
2154: 单身狗线下聚会 题目描述 马上就到七夕节了,单身狗们决定聚一聚.但是它们沉迷B站上的lo娘,他们每沉迷 ai 单身狗时间(这是它们专业计时)后就会休息 单身狗时间.它们想找到一个时间正好他 ...
- linux加载字体
将解压后的文件夹cp到/usr/share/fonts目录下,然后cd到/usr/share/fonts/ziti目录下执行:mkfontscalemkfontdirfc-cache 在linux,把 ...
- vue 有条件加载组件 执行某方法后再渲染组件
<component :is="currentCom"></component> import Grid from './component/grid' ...
- springboot2.0入门(八)-- profile启动文件配置
一.不同环境使用不同配置文件 将application.yml文件拷贝三份,在文件末尾分别对应开发/生产/测试,dev/prod/test/文件夹,其中application.yml 中默认激活开发环 ...
- python库下载网址
wheel文件下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/