951-MyCAT入门及应用
https://www.imooc.com/learn/951
简介:本课程从实际生产环境应用MyCAT入手,讲解MyCAT的基础知识和MyCAT的基本应用操作,本课程的目标就是“看得懂、学得会、做得出”,为后续的学习打下夯实的基础。
目录
第1章 课程介绍
本章节主要介绍课程结构
1-1 课程介绍
学习目的:
- 掌握在数据库负载增大时的处理方法
- 理解MyCat的基础概念(分库、分表、逻辑库、逻辑表)
- 掌握MyCat的基础配置和监控方法
第2章 MyCAT介绍
本章节主要介绍MyCAT的主要应用场景和优势,用来帮助大家了解MyCAT具体应用在什么样的生产环境中。
2-1 MyCAT前世今生
阿里开源数据库中间件产品:
2008年:Amoeba。
阿里使用多台MySQL数据库来替代Oracle数据库
充当MySQL分布式数据库中间层,主要应用在访问层,充当应用程序与数据库之间的代理
具有负载均衡、高可用、SQL过滤,支持对后端数据库的读写分离
2012年:Cobar
应用3000+台服务器的集群规模
明天可处理超过10亿的数据库访问
2013年:MyCat
解决了Cobar在高并发的情况下假死
前后端的……并不是统一的
2-2 MyCAT的主要功能
MyCat的主要作用:
实现了MySQL通信协议的分布式数据库系统中间层
数据库中间层:在架构中的位置,位于前端应用和后端数据库之间的一个应用软件
数据库中间层:作用,读写分离、负载均衡、数据库连接池(统一控制数据库的连接数量)、屏蔽后端数据库的变更、连接多种类型数据库(如MSSQL、MongoDB等包括非关系型数据库)
实现数据库的读写分离
MySQL主从复制集群(写操作在主数据库中执行、读操作在从数据库中执行)
主从复制实现原理
MyCat支持读数据库的负载均衡
这种情况多出现在一主多从的架构上,将读负载在多个服务器上进行负载均衡
MyCat支持后端MySQL高可用
此处的高可用不同于通过MHA和3M方式复制架构来实现的高可用。在MHA和3M架构中,当主节点宕机之后是可以自动从多个从节点中选择一个新的主节点,并且将其他从节点对这个新的主节点重新进行同步。
MyCat对后端数据库的高可用是指,在配置的时候,除了主节点之外,可以指定从节点,实现写操作。当主节点宕机之后,MyCat会把写的SQL路由到配置的写从节点上,并且不支持把其他的从节点对新节点进行主从同步。
数据库垂直拆分
垂直切蛋糕…
数据库水平拆分(分库、分表)
水平切蛋糕…
将一个数据库通过一定规则进行切分成多个数据库。比如,对userId取模来进行切分,将user表均匀的分到三个数据库中(三个库的表结构是完全一致的)。
前端应用通过MyCat以及切分规则来对切分后的数据库进行访问。
MyCat统一实现了切分逻辑,而不同在前端应用中实现切分逻辑。
2-3 MyCAT的主要功能
见【2-2 MyCAT的主要功能】
2-4 MyCAT的主要功能
见【2-2 MyCAT的主要功能】
2-5 MyCAT的应用场景
需要进行读写分离的场景
在一台数据库服务器上进行读写混合操作时,数据库读写性能大幅下降,并且读负载明显高于写负载
MyCat支持多种后端MySQL集群方案来进行读写分离,如一主一从、一主多从、主主复制、PXC集群等等
需要进行分库分表的场景(切分)
最大支持单表1000亿的操作
多租户场景(软件架构)
在多用户的环境下,使用共同的数据库系统的组件,并且可以确保各个 用户之间具有数据隔离性。如云服务。
数据统计系统
HBASE的一种替代方案
HBASE是基于Hadoop的一种分布式列存储数据库
MySQL关系型数据库为行存储
需要使用同样的方式查询多种数据库的场景
MyCat可以同时支持多种数据库,如关系型数据库和NoSQL非关系型数据库。MyCat只向应用提供一个IP访问地址,而数据库存储方式的实现则可以使用各种方案。
2-6 MyCAT的优势
- 基于阿里的Cobar系统开发
- 开发社区活跃
- 完全开源可以自定义开发
- 支持多种关系型及NoSQL数据库
- 使用JAVA开发,可以部署在多种系统上。建议部署在Linux
- 具有在多种行业和项目中应用的成功案例
第3章 MyCAT基础
本章节主要讲解MyCAT的基础知识,包括MyCAT的安装,启动配置和应用等。通过老师逻辑清晰的讲解,让大家理解并掌握MyCAT在实战中的基本应用。
3-1 MyCAT的基本概念
MYCAT中的数据库一逻辑库
user_db是逻辑数据库;db01、db02、db03是物理数据库
MyCat中只保存逻辑库的定义,不保存数据,具体的数据存储在物理数据库中
MYCAT中的数据库一逻辑表
可以用数据库中视图的概念理解
3-2 MyCAT的关键特性
支持SQL92标准
支持MySQL集群
支持JDBC连接数据库
支持NOSQL数据库
支持自动故障切换,高可用性
支持读写分离
支持全局表
将较少变动的数据统一存储起来
支持独有的基于ER关系的分片策略
根据实体关系ER模型,将相关的表存储在一个分片上,避免调用时跨分片
支持一致性HASH分片
多平台支持,部署简单方便
支持全局序列号
将多个数据库表的自增ID统一起来,不出现重复ID
3-3 安装MyCAT
安装Java环境
下载MyCat
新建MyCat用户
在Linux系统环境下,最好为每一款软件都独立的建立一个运行账号。既安全又可以对账号进行资源的限制
解压MyCat
配置环境变量
Java的HOME目录
Java的CLASSPATH目录
MyCat的HOME目录
启动MyCat
3-4 MyCAT安装
java -version
yum install java-1.7.0-openjdk
wget http://dl.mycat.io/1.6.7.1/Mycat-server-1.6.7.1-release-20190627191042-linux.tar.gz
adduser mycat # 建立mycat用户
tar -xzvf Mycat-server-1.6.7.1-release-20190627191042-linux.tar.gz # 解压MyCat安装文件
mv mycat /usr/local/ # 移动MyCat安装文件到/usr/local/
chown mycat:mycat -R mycat # #改变当前文件夹属主和属组
vi /etc/profile # 配置环境变量
export JAVA_HOME=/usr
export MYCAT_HOME=/usr/local/mycat
Linux系统安装任何一种软件最好都要新建一个独立用户,不要用root运行,不然会产生不安全的因素
3-5 MyCAT启动 (03:48)
MyCat两种启动方式:
基于脚本的启动方式
启动脚本:
$MYCAT_HOME/bin/startup_nowrap.sh ==> /usr/local/mycat/bin/startup_nowrap.sh
脚本参数:
当运行MyCat时,报内存不足或者是内存溢出异常
JAVA_OPTS="-server -Xms1G -Xmx2G -XX:MaxPermSize=64M -XX:+AggressiveOpts -XX:MaxDirectMemorySize=2G"
# 切换到mycat用户 su - mycat cd /usr/local/mycat # 通过脚本启动MyCat bin/startup_nowrap.sh # 查看进程信息 ps -ef # 查看日志 cd /usr/local/mycat/logs more mycat.log
bin下已打包的mycat
3-6 MyCAT配置文件
- schema.xml用于配置逻辑库表及数据节点,数据源
- rule.xml用于配置表的分片规则
- server.xml用于配置服务器权限
schema.xml文件
定义逻辑库表
逻辑表是要依赖于逻辑库存在的。
如果数据库不需要进行分片,只进行读写分离,此时不用配置
标签,而只保留
标签 <schema> <table> </table> </schema>
定义数据节点
定义MyCat的分片节点,一个数据节点就代表着一个独立的分片。其内容包括数据库节点的名字、数据源真实物理数据库的名称
<dataNode> </dataNode>
定义数据节点的物理数据源
定义了一组主机节点,是真实物理数据库的实例。
一个
标签所指定的主机就是一组真实的MySQL数据库集群 读写分离配置、心跳检测。。。
<dataHost> </dataHost>
rule.xml文件
定义表使用的分片规则
<tableRule name=""> </tableRule>
定义分片算法
<function name=""> </function>
server.xml文件
用于定义系统配置
系统端口号、系统使用内存大小、timeout时间
<system> <property name=""> </property> </system>
用于定义连接MyCat的用户信息
用户名字、密码
只有在server.xml中存在的用户才可以通过MyCat连接到后端数据库
<user> </user>
3-7 MyCAT读写分离
三台服务器:MyCat服务器(node1)、两台MySQL服务器(Master-node2、Slave-node3)
显示xml文件:
ls -lh *xml
MyCat实现数据库读写分离只需配置两个文件:schema.xml、server.xml
<!-- /usr/local/mycat/conf/schema.xml --> <mycat:schema> <!-- 配置逻辑库USERDB --> <schema name="USERDB" checkSQLschema="false" sqlMaxLimit="100" dataNode="dn1"></schema> <!-- 定义数据节点node1 --> <dataNode name="dn1" dataHost="node1" database="user_db" /> <!-- 定义数据库集群 --> <dataHost name="node1" maxCon="1000" minCon="10" blance="1" writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100"> <heartbeat>select user()</heartbeat> <writeHost host="10.102.13.3" url="10.102.13.3:3306" user="im_user" password="123456"> <readHost host="10.102.13.4" url="10.102.13.4:3306" user="im_user" password="123456" /> </writeHost> <writeHost host="10.102.13.4" url="10.102.13.4:3306" user="im_user" password="123456" /> </dataHost> </mycat:schema>
注:
sqlMaxLimit="100"
每一条SQL只返回100行记录如果数据库进行了分片操作,查询数据会从所有分片中查询。此时会对系统造成负载
dataNode="dn1"
定义了数据节点dn1blance="1"
定义了是否对后端多个从数据库进行负载均衡。1是0否<heartbeat>
定义了如何监测后端数据库是否健康user="im_user" password="123456"
定义了后端物理数据库的用户名和密码
<!-- /usr/local/mycat/conf/server.xml --> <mycat:server> <system> <property name="serverPort">3306</property> <property name="managerPort">9066</property> <property name="nonePasswordLogin">0</property> <property name="useHandshakeV10">1</property> <property name="useSqlStat">0</property> <property name="useGTob]eTablecheck">0</property> <property name="sequnceHandlerType">2</property> <property name="subqueryRelationshipcheck"> fal se</property> <property name="processorBufferPoolType">0</property> <property name="handlepistributedTransactions">0</property> <property name="useoffHeapForMerge">1</property> <property name="memoryPageSize">64k</property> <property name="spi11sFileBuffersize">1k</property> <property name="usestreamoutput">0</property> <property name="systemReserveMemorysize">384m</property> <property name="usezkSwitch">false</property> </system> <user name="root" defaultAccount="true"> <property name="password">123456</property> <property name="schemas">USERDB</property> </user> <user name="mc_user"> <property name="password">123456</property> <property name="schemas">USERDB</property> <property name="readOnly">true</property> </user> </mycat:server>
注:
<user>
定义的用户在后端数据库中实际并不存在
重启MyCat:
# /usr/local/mycat bin/mycat stop bin/mycat start
通过MyCat写数据,然后再读取:
# /root/script/init_data.py import MySQLdb from faker import Faker try: conn = MysQLdb.connect(host='127.0.0.1', user='root',passwd='123456', db='USERDB', charset="utf8") cursor=conn. cursor(MySQLdb.cursors.Dictcursor) except MysQLdb.Error, e: print "Error %d: %s \n" % (e.args[0],e. args[1]) try: faker=Faker() # write data for i in range(0, 10): InSQL=""" insert into customer_login(login_name, password, user_stats) VALUES('%s', md5('%s'), 1) """%(faker.name(), faker.ean13()) print InSQL cursor.execute(InSQL) cursor.execute('commit') # read data for i in range(0, 10): sQLstr=""" select login_name from customer_login where customer_id = %d; """%(i) cursor.execute(SQLstr) resuit = cursor. fetchall() print result except MysQLdb.Error,e: print "Error %d: %s \n" % (e.args[0], e.args[1]) finally cursor.close() conn.close()
执行程序:
# /root/script python init_data.py
查看MyCat日志:
more /usr/local/mycay/logs/mycat.log
跟踪日志文件:
tailf /usr/local/mycay/logs/mycat.log
3-8 MyCAT读写分离总结
步骤:
修改schema.xml文件(/usr/local/mycat/conf/schema.xml)
对后端数据库的逻辑库、数据节点、数据主机节点进行配置
由于未进行分片操作,只需配置
标签,无需配置 标签
修改server.xml文件(/usr/local/mycat/conf/server.xml)
MyCat向应用程序提供的服务端口、MyCat用户
3-9 MyCAT管理
使用MySQL客户端管理MyCat
- 管理端口:
<property name="managerPort">9066</property>
- 命令:
mysql -uroot -p123456 -h127.0.0.1 -P9066
- 查看管理命令:
show @@help
常用管理命令
动态加载配置文件:
reload @@config
动态加载MyCat配置文件,但是并不是所有的配置文件都能够通过该命令加载的,某些还需要对MyCat进行重启,后期还会有MyCat高可用方案避免重启对应用程序的影响。
查看数据节点:
show @@datanode
查看MyCat中配置的节点详情
查看后端数据库:
show @@datasource
查看MyCat后端的物理数据库的详情
查看后端数据库连接:
show @@backend
查看MyCat后端的数据库的连接情况
第4章 MyCAT日志分析
通过学习MyCAT日志,掌握MyCAT运行时的相关信息以及应用日志对MyCAT运行时的错误进行跟踪处理。
4-1 MyCAT日志
配置MyCat日志:
MyCat使用Apache log4j项目管理日志
MyCat配置文件:conf/log4j2.xml
log4j2.xml作用
配置日志格式
<PatternLayout> <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %5p [%t] - %m%n</Pattern> </PatternLayout>
2019-07-07 15:22:02.485 DEBUG [Timer1] - con query sql:select user() to con:MySQLConnection
注:
- %d:定义时间。如:2019-07-07 15:22:02.485
- %5p:日志级别。如:DEBUG
- %t:线程信息。如:[Timer1]
- %m:代码提示信息。如:con query sql:select user() to con:MySQLConnection
- %n:回车符
配置日志级别
<asyncRoot level="info" includeLocation="true" />
ALL < Trace < Debug < Info < Warn < Error < Fatal < OFF
注:
- 一般设置Debug模式,最强也就是Info类型
4-2 MyCAT日志
MyCat启动过程中输出的日志
10:45:06.377 INFO [ WrapperSimpleAppMain]-total resouces of dataHost nodel is:3 10:45:06.389 INFO [ WrapperSimpleAppMain]-create layer cache pool TableID2DataNodeCache of type encache, default cache size 10000, default expire seconds18000 10:45:06.391 INFO [ WrapperSimpleAppMain]-create child Cache: TESTDB_ORDERS for layered cache TableID2DataNodeCache, size 50000, expire seconds 18000 10:45:06.523 DEBUG [ WrappersimpleAppMain]-Configuring ehcache from ehcache. xml found in the classpath: file:/usr/1ocal/mycat/conf/ehcache. xml 10:45:06.525 DEBUG [ WrappersimpleAppMain]-Configuring ehcache from URL: file:/usr/1ocal/mycat/conf/ehcache. xmll 10:45:06.525 DEBUG [ WrappersimpleAppMain]-Configuring ehcache from InputStream 10:45:06.652 DEBUG [ WrapperSimpleAppMain]-Ignoring ehcache attribute xmlns: mycat 10:45:06.653 DEBUG [ WrapperSimpleAppMain]-Ignoring ehcache attribute xmlns: xsi 10:45:06.653 DEBUG [ WrapperSimpleAppMain]-Ignoring ehcache attribute maxEntriesLocalHeap 10:45:06.656 DEBUG [ WrapperSimpleAppMain]-Ignoring ehcache attribute xsi: noNamespaceSchemalocation 10:45:06.689 DEBUG [ WrappersimpleAppMain]-Creating new CacheManager with default config 10:45:06.723 DEBUG [ WrapperSimpleAppMain]-propertiesstring is null. 10:45:06.812 DEBUG[ WrapperSimpleAppMain]-Cacheuriter factory not configured. Skipping... 10:45:06.812 DEBUG [ WrappersimpleAppMain]-Initialized net. sf. ehcache. store. NotifyingMemoryStore for SQLRouteCache 10:45:06.813 DEBUG [ WrappersimpleAppMain]-Initialised cache: SQLRouteCache 10:45:06.828 INFO [ WrappersimpleAppMain]-dyna class load from./catlet, and auto check for class file modified every 60 seconds 10:45:06.830 DEBUG [ WrappersimpleAppMain]-baseDir./tmlogs/ 10:45:06.830 DEBUG[ WrappersimpleAppMain]-baseName tmlog
注:
- total resouces of dataHost nodel is:3。3个主机节点
MyCat线程数
10:45:06.875 INFO[ WrapperslimpleAppMain]-MyCat is ready to startup.…. 10:45:06.875 INFO [ WrappersimpleAppMain]-Startup processors..., total processors:48, aio thread pool size:96 each process allocated socket buffer pool bytes,a page size:2097152 a page's chunk number(Pagesize/Chunksize) is:512 buffer page's number is:960
注:
- total processors:48。线程数为48,默认为线程数等于CPU核数。
- aio thread pool size:96。aio进程池数量为CPU核数的两倍
server.xml中配置MyCat的启动参数
10:45:06.875 INFO[ WrapperSimpleAppMain]-sysconfig params: Systemconfig [processorBufferLocalPercent=100, frontSocketSoRcvbuf=1048576, frontSocketSoSndbuf=4194304, backSocketSoRcvbuf=4194384, backSocketSosndbuf=1048576, frontSocketNoDelay=1, backSocketNoDelay=1, maxStringLiteralLength=65535, frontwriteQueueSize=2048, bindIp=0.0.0.0, serverPort=3306, managerPort=9066, charset=utf8, processors=48, processorExecutor=96, timerExecutor=2, managerExecutor=2, idleTimeout=1800000, catletC1assCheckSeconds=60, sqlExecuteTimeout=300, processorCheckPeriod=1000, dataNodeIdleCheckPeriod=300000, dataNodeHeartbeatPeriod=10000, clusterHeartbeatUser=HEARTBEAT_USER_, clusterHeartbeatPass=_HEARTBEAT_PASS_, clusterHeartbeatPeriod=5000, clusterHeartbeatTimeout=10000, clusterHeartbeatRetry=10, txIsolation=3, parserCommentVersion=50148, sq1RecordCount=10, bufferPoolPageSize=2097152, bufferPoolChunkSize=4096, bufferPoolPageNumber=960, maxResultSet=524288, bigResultsizesqlCount=10, bufferUsagePercent=80, flowControlRejectStrategy=0, clearBigSqLResultSetMapMS=600000, defaultMaxLimit=100, sequnceHandlerType=2, mutiNodeLimitType=e, mutiNodePatchSize=100, defaultSqlParser=druidparser, usingArO=0, packetHeaderSize=4, maxPacketsize=16777216, mycatNodeId=1]
注:
- serverPort=3306。MyCat对外提供服务的端口号
- managerPort=9066。MyCat管理端口
- charset=utf8。MyCat默认字符集
- processors=48。MyCay进程数
- processorExecutor=96。MyCay进程池大小
- idleTimeout=1800000。应用程序与MyCat连接超时时间
- defaultMaxLimit=100。MyCat默认返回结果集行数
- maxPacketsize=16777216。最大包大小,一定不能大于在MySQL中配置的大小。
MyCat监听端口的启动
10:45:08.158 INFO [WrapperSimpleAppMain]-using nio network handler 10:45:08.224 INFO [WrapperSimpleAppMain]-$ MyCatManager is started and listening on 9066 10:45:08.224 INFO[WrappersimpleAppMain]-$_MyCatserver is started and listening on 3306
MyCat对后端连接池的初始化
10:45:08.224 INFO[WrapperSimpleAppMain]-============================ 10:45:08.224 INFO[WrapperSimpleAppMain]-Initialize dataHost... 10:45:08.224 INFO[WrappersimpleAppMain]-init datahost:nodel to use datasource index:1 10:45:08.225 INFO[WrappersimpleAppMain]-init backend myqsl source,create connections total 10 for 192.168.13.4 index:1 10:45:08.226 INFO[WrappersimpleAppMain]-no ilde connection in pool, create new connection for 192.168.13.4 of schema user_db 10:45:08.227 INFO[WrappersimpleAppMain]-no ilde connection in pool, create new connection for 192.168.13.4 of schema user_db 10:45:08.228 INFO[WrappersimpleAppMain]-no ilde connection in pool, create new connection for 192.168.13.4 of schema user_db 10:45:08.229 INFO[WrappersimpleAppMain]-no ilde connection in pool, create new connection for 192.168.13.4 of schema user_db 10:45:08.271 INFO[$_NIOREACTOR-1-RW]-connected successfuly MysQLConnection[id=1, 1astTime=1520217908270, user=im_user, schema=user_db, old shema=user_db, borrowed=true, fromslaveDB=false, threadId=2233481, harset=utf8, txIsolat ion=3, autocommit=true, attachment=nul1, respHandler=null, host=192.168.13.4, port=3306, statussync=null, uriteQueue=e, modifiedSQLExecuted=false] 10:45:08.271 INFO[$_NIOREACTOR-5-RW]-connected successfuly MysQLConnection[id=5, 1astTime=152021790827e, er=imuser, schema=user_db, old shema=user_db, borrowed=true, fromslaveDB=false, threadId=2233482, harset=utf8, txIsolat ion=3, autocommit=true, attachment=nul1, respHandler=nul1, host=192.168.13.4, port=3306, statussync=null, writeQueue=0, modifiedSQLExecuted=false]
MyCat初始化完成之后的输出
10:45:08.334 INFO [WrapperSimpleAppMain]-init result :finished 10 success 10 target count:10 10:45:08.334 INFO [WrappersimpleAppMain]-nodel index:1 init success
MyCat对后端数据库进行心跳检测
10:45:08.347 INFO [ Timer1]-no ilde connection in pool, create new connection for 192.168.13.3 of schema user db 10:45:08.348DEBUG[ Timer1]-con query sql: select user() to con: MysQLConnection [ id=2, 1astTime=1520217908348, iser=im_user, schema=user_db, old shema=user_db, borrowed=true, fromslaveDB=false, threadId=2233483, charset=utf8, txIsol ation=3, autocommit=true, attachment=nul1, respHandler=nul1, host=192.168.13.4, port=3306, statussync=null, writeQueue=0,m odifiedSQLExecuted=false] 10:45:08.348 INFO[$_NIOREACTOR-11-RW]-connectionAcquired MySQLConnection [ id=11,1astTime=1520217908348, er=im_user, schema=user_db, old shema=user_db, borrowed=true, fromslaveDB=true, threadId=2233490, charset=utf8, txIsolatio 1=3, autocommit=true, attachment=nul1, respHandler=null, host=192.168,13.4, port=3306, statussync=nul1, writeQueue=e, modif iedSQLExecuted=false] 10:45:08.373 INFO [ Timer1]-no ilde connection in pool, create new connection for 192.168.13.4 of schema user_db 18:45:08.377 DEBUG[$_NTOREACTOR-12-RW]-con query sql: select user() to con: MysQLconnection [ id=12, lastTime=1520217908377, user=im_user, schema=user_db, old shema=user_db, borrowed=true, fromslaveDB=false, threadId=908148, charset= utf8, txIsolation=3, autocommit=true, attachment=nul1, respHandler=nu11, host=192.168.13.3, port=3306, statusSync=nul1, wri teQueue=e, modifiedSQLExecuted=false]
应用程序登录到MyCat输出的信息
14:16:48.257 INFO[$_NIOREACTOR-7-RW]-ServerConnection [ id=6, schema=USERDB, host=127.0.0.1, user=root, txIsolation=3, autocommit=true, schema=USERDB]'root' login success 14:16:48.259 DEBUG [$_NIOREACTOR-7-RW]-ServerConnection [ id=6, schema=USERDB, host=127.0.0.1, user=root, txIsolation=3, autocommit=true, schema=USERDB] show databases 14:16:48.260 DEBUG [$_NIOREACTOR-7-RW]-ServerConnection [ id=6, schema=USERDB, host=127.0.0.1, user=root, txIsolation=3, autocommit=true, schema=USERDB] show tables 14:16:48.260 DEBUG[$_NIOREACTOR-7-RW]-ServerConnection [ id=6, schema=USERDB, host=127.0.0.1, user=root, txIsolation=3, autocommit=true, schema=USERDB] show tables, route={ 1->dnl{ show tables} } rrs
向MyCat发送一条SQL语句输出的日志
14:16:48.262 DEBUG [$_NIOREACTOR-7-RW]-ServerConnection [ id=6, schema=USERDB, host=127.0.0.1, user=root, txIsolation=3, autocommit=true, schema=USERDB] select * from customer_login where login_name=' John Miller 14:16:48.263 DEBUG[$_NIOREACTOR-7-RW]-SQLRouteCache miss cache, key: USERDB select * from customer_1ogin where login_name='John Miller' 14:16:48.263 DEBUG [$_NIOREACTOR-7-RW]-ServerConnection [ id=6, schema=USERDB, host=127.0.0.1, user=root, txIsolation=3, autocommit=true, schema=USERDB] select * from customer_login where 1ogin_name=' John Miller', route={ 1-> dnl{ select * from customer_login where login_name=' John Miller} } rrs
具体SQL执行过程
14:16:48.263 DEBUG [$_NIOREACTOR-7-RW]-select read source 192.168.13.4 for dataHost: nodel 14:16:48.265 DEBUG[$_NIOREACTOR-13-RW]-release connection MySQLConnection [ id=13,1astTime=1520230608256, user=im_user, schema=user_db, old shema=user_db, borrowed=true, fromslaveDB=true, threadId=2233491, charset=utf8, txIsolation=3, autocommit=true, attachment=dnl{ select * from customer_login where login_name=' John Miller'}, respHandler=SingleNodeHandler [ node=dn1{ select * from customer_login where login_name='John Miller'}, packetId=8], host=192.168.13.4, port=3306, statussync=null, writeQueue=0, modifiedSQLExecuted=false]
第5章 课程总结
本章节主要对课程中涉及到的全部知识点进行知识总结。并介绍进一步学习MyCAT的学习途径。
5-1 总结
已学内容:
- MyCat起源
- MyCat基本概念
- 如何安装、启动、配置MyCat
- 利用MyCat实现对后端数据库的读写分离
- MyCat主要功能和应用场景
未讲内容:
- 如何利用MyCat对后端数据库进行分片
- 如何对分片集群进行备份
- 分片集群中宕机一台服务器会有什么影响
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 tuyrk@qq.com文章标题:951-MyCAT入门及应用
文章字数:5.5k
本文作者:神秘的小岛岛
发布时间:2019-07-09, 21:49:07
最后更新:2019-11-05, 17:28:24
原始链接:https://www.tuyrk.cn/imooc/951-MyCat/版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。