mycat接oracle和mysql多个实例
Mycat 后面接一个Oracle实例与一个MySQL实例,假设用户表,订单表,转账记录表,Oracle字符集为GBK的,MySQL字符集则要求UTF8的
完成用户表与订单表到MySQL的迁移过程,要求导数据是通过命令行连接Mycat来完成的
oracle
scott/scott103@10.0.1.103/grs
select userenv('language') from dual;
SIMPLIFIED CHINESE_CHINA.AL32UTF8
--oracle tables
CREATE TABLE UC_USER(ID number,UC_NAME VARCHAR(64),CREATE_TIME DATE);
CREATE TABLE UC_ORDER(ID number,UC_ID number,SHOP_NAME VARCHAR(64),CREATE_TIME DATE);
CREATE TABLE TRADERS(ID number,UC_ID number,ORDER_ID number, FEE number,TRADE_STATUS char(1),CREATE_TIME DATE);
INSERT INTO UC_USER(ID,UC_NAME,CREATE_TIME)VALUES(1,'张三',SYSDATE);
INSERT INTO UC_USER(ID,UC_NAME,CREATE_TIME)VALUES(2,'李四',SYSDATE);
INSERT INTO UC_ORDER(ID,UC_ID,SHOP_NAME,CREATE_TIME)VALUES(1,1,'mycat技术权威指南书籍',SYSDATE);
INSERT INTO UC_ORDER(ID,UC_ID,SHOP_NAME,CREATE_TIME)VALUES(2,2,'mysql高性能第三版',SYSDATE);
INSERT INTO TRADERS(ID,UC_ID,ORDER_ID,FEE,TRADE_STATUS,CREATE_TIME)VALUES(1,1,1,59,1,SYSDATE);
INSERT INTO TRADERS(ID,UC_ID,ORDER_ID,FEE,TRADE_STATUS,CREATE_TIME)VALUES(2,2,2,119,1,SYSDATE);
mycat中配置oracle、mysql数据源
<table name="UC_USER" primaryKey="ID" type="global" dataNode="dn_oracle_1" />
<table name="UC_ORDER" primaryKey="ID" type="global" dataNode="dn_oracle_1" />
<table name="TRADERS" primaryKey="ID" type="global" dataNode="dn_oracle_1" />
<dataNode name="dn_oracle_1" dataHost="dn_oracle_1" database="grs" />
<dataHost name="dn_oracle_1" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="oracle" dbDriver="jdbc" switchType="1" slaveThreshold="100">
<heartbeat>select 1 from dual </heartbeat>
<connectionInitSql>alter session set nls_date_format='yyyy-mm-dd hh24:mi:ss'</connectionInitSql>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="jdbc:oracle:thin:@10.0.1.103:1521:grs" user="scott" password="scott103" >
</writeHost>
</dataHost>
--mysql tables
mysql> CREATE TABLE UC_USER_2(ID int, UC_NAME VARCHAR(64),CREATE_TIME DATETIME);
mysql> CREATE TABLE UC_ORDER_2(ID int,UC_ID int,SHOP_NAME VARCHAR(64),CREATE_TIME DATETIME);
mysql> CREATE TABLE TRADERS_2(ID int,UC_ID int,ORDER_ID int, FEE int,TRADE_STATUS char(1),CREATE_TIME DATETIME);
mycat中配置oracle、mysql数据源
<table name="UC_USER_2" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
<table name="UC_ORDER_2" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
<table name="TRADERS_2" primaryKey="ID" type="global" dataNode="dn1,dn2,dn3" />
<dataNode name="dn1" dataHost="localhost0" database="db1" />
<dataNode name="dn2" dataHost="localhost0" database="db2" />
<dataNode name="dn3" dataHost="localhost0" database="db3" />
<dataHost name="localhost0" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>show slave status </heartbeat>
<!-- can have multi write hosts -->
<writeHost host="hostM1" url="10.0.1.134:3306" user="system"
password="mysql">
<!-- can have multi read hosts -->
<readHost host="hostS1" url="192.168.3.110:3306" user="system" password="mysql" />
</writeHost>
<!--writeHost host="hostM2" url="192.168.3.110:3306" user="system"
password="mysql" > -->
<!--readHost host="hostS2" url="10.0.1.134:3306" user="system" password="mysql" /> -->
<!--/writeHost> -->
<!-- <writeHost host="hostM2" url="localhost:3316" user="root" password="123456"/> -->
</dataHost>
<dataHost name="135_host" maxCon="1000" minCon="10" balance="0"
writeType="0" dbType="mysql" dbDriver="native" switchType="1" slaveThreshold="100">
<heartbeat>select user() </heartbeat>
<writeHost host="hostM2" url="10.0.1.135:3307" user="system"
password="mysql">
</writeHost>
</dataHost>
加载oracle的lib包
需要把oracle的jar包放到mycat安装目录下,一般是用这个ojdbc14.jar,放到/usr/mysql/mycat/lib目录下面,然后重新加载下mycat生效。
[root@hongquan lib]# ls ojdbc14.jar
ojdbc14.jar
[root@hongquan lib]# pwd
/usr/local/mycat/mycat/lib
配置并重启
mysql> show @@datanode;
+-------------+-----------------+-------+--------+--------+------+------+---------+------------+----------+---------+---------------+
| NAME | DATHOST | INDEX | TYPE | ACTIVE | IDLE | SIZE | EXECUTE | TOTAL_TIME | MAX_TIME | MAX_SQL | RECOVERY_TIME |
+-------------+-----------------+-------+--------+--------+------+------+---------+------------+----------+---------+---------------+
| dn1 | localhost0/db1 | 0 | mysql | 0 | 2 | 1000 | 5 | 0 | 0 | 0 | -1 |
| dn10 | 135_host/db10 | 0 | mysql | 0 | 5 | 1000 | 8 | 0 | 0 | 0 | -1 |
| dn2 | localhost0/db2 | 0 | mysql | 0 | 1 | 1000 | 1 | 0 | 0 | 0 | -1 |
| dn3 | localhost0/db3 | 0 | mysql | 0 | 2 | 1000 | 2 | 0 | 0 | 0 | -1 |
| dn4 | localhost0/db4 | 0 | mysql | 0 | 1 | 1000 | 1 | 0 | 0 | 0 | -1 |
| dn5 | localhost0/db5 | 0 | mysql | 0 | 1 | 1000 | 1 | 0 | 0 | 0 | -1 |
| dn6 | localhost0/db6 | 0 | mysql | 0 | 1 | 1000 | 1 | 0 | 0 | 0 | -1 |
| dn7 | localhost0/db7 | 0 | mysql | 0 | 1 | 1000 | 1 | 0 | 0 | 0 | -1 |
| dn8 | localhost0/db8 | 0 | mysql | 0 | 1 | 1000 | 1 | 0 | 0 | 0 | -1 |
| dn9 | 135_host/db9 | 0 | mysql | 0 | 5 | 1000 | 5 | 0 | 0 | 0 | -1 |
| dn_oracle_1 | dn_oracle_1/grs | 0 | oracle | 0 | 10 | 1000 | 10 | 0 | 0 | 0 | -1 |
+-------------+-----------------+-------+--------+--------+------+------+---------+------------+----------+---------+---------------+
防止乱码配置,在server.xml里面配置:
<property name="charset">utf8</property>
从oracle迁移出来
在mycat命令行迁移出来
mysql -h127.0.0.1 -P8066 -usystem -pmysql -DTESTDB -s -N -e "select * from UC_USER" > /tmp/UC_USER.txt
导入mysql
在mycat命令行执行load data infile '/tmp/UC_USER_2.txt' into table UC_USER_2
mysql> load data infile '/tmp/UC_USER_2.txt' into table UC_USER_2;
在mycat平台上从oracle迁移到mysql中文正常
指导思想:
Mycat对于数据库而言就是客户端,一般来讲客户端字符编码与数据库服务端一致就不会有什么问题,或者是严格超集,
保证插入到数据库不因转码而丢失。客户端、系统终端、数据库三者字符庥得协调,否则不一致的话,会有字符集转换的问题,
有时候,显示正确的,但不一定在数据库就保存正确,或者保存到数据库的数据编码正确,没准显示为乱码。这就意味着,
在oracle里面是gbk或者latin1啥都没有关系,只要做好以下3点:
(1),在迁移到mysql里面,在mycat平台上从oracle导出时候字符集设置为utf8
(2),在mycat平台上导入到mysql字符集也要设置为utf8
(3), 然后在mycat平台上查看数据也要设置字符集为utf8
做好了以上3点,三而合一,这样就能正常显示中文了。
设定好utf8,--default-character-set=utf8:
mysql -h127.0.0.1 -P8066 -usystem -pmysql -DTESTDB -s -N --default-character-set=utf8 -e "select * from UC_USER" > /tmp/UC_USER_2.txt
导入的时候,在命令行也设定好utf8,set names utf8;
mysql> set names utf8;
2016-12-23 00:01:35.648 DEBUG [Timer0] (io.mycat.backend.jdbc.JDBCHeartbeat.heartbeat(JDBCHeartbeat.java:109)) - JDBCHeartBeat con query sql: select 1 from dual
2016-12-23 00:01:36.461 INFO [$_NIOREACTOR-0-RW] (io.mycat.net.handler.FrontendAuthenticator.success(FrontendAuthenticator.java:194)) - [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=4,host=10.0.1.134,port=9066,schema=TESTDB]'system' login success
2016-12-23 00:01:36.465 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:288)) - [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=4,host=10.0.1.134,port=9066,schema=TESTDB] show databases
2016-12-23 00:01:36.465 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.manager.ManagerQueryHandler.query(ManagerQueryHandler.java:58)) - [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=4,host=10.0.1.134,port=9066,schema=TESTDB]show databases
2016-12-23 00:01:36.468 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:288)) - [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=4,host=10.0.1.134,port=9066,schema=TESTDB] show tables
2016-12-23 00:01:36.468 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.manager.ManagerQueryHandler.query(ManagerQueryHandler.java:58)) - [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=4,host=10.0.1.134,port=9066,schema=TESTDB]show tables
2016-12-23 00:01:36.469 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.net.FrontendConnection.query(FrontendConnection.java:288)) - [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=4,host=10.0.1.134,port=9066,schema=TESTDB] show @@heartbeat
2016-12-23 00:01:36.469 DEBUG [$_NIOREACTOR-0-RW] (io.mycat.manager.ManagerQueryHandler.query(ManagerQueryHandler.java:58)) - [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=4,host=10.0.1.134,port=9066,schema=TESTDB]show @@heartbeat
2016-12-23 00:01:36.474 WARN [$_NIOREACTOR-0-RW] (io.mycat.net.NIOReactor$RW.run(NIOReactor.java:107)) - caught err:
java.lang.NullPointerException
at io.mycat.manager.response.ShowHeartbeat.getRows(ShowHeartbeat.java:138) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.manager.response.ShowHeartbeat.response(ShowHeartbeat.java:112) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.manager.handler.ShowHandler.handle(ShowHandler.java:135) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.manager.ManagerQueryHandler.query(ManagerQueryHandler.java:69) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.net.FrontendConnection.query(FrontendConnection.java:317) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.net.FrontendConnection.query(FrontendConnection.java:337) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.net.handler.FrontendCommandHandler.handle(FrontendCommandHandler.java:71) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.manager.ManagerConnection.handle(ManagerConnection.java:54) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.net.AbstractConnection.onReadData(AbstractConnection.java:321) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.net.NIOSocketWR.asynRead(NIOSocketWR.java:190) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.net.AbstractConnection.asynRead(AbstractConnection.java:273) ~[Mycat-server-1.6-RELEASE.jar:?]
at io.mycat.net.NIOReactor$RW.run(NIOReactor.java:102) ~[Mycat-server-1.6-RELEASE.jar:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_101]
2016-12-23 00:01:36.477 INFO [$_NIOREACTOR-0-RW] (io.mycat.net.AbstractConnection.close(AbstractConnection.java:508)) - close connection,reason:program err:java.lang.NullPointerException ,[thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=4,host=10.0.1.134,port=9066,schema=TESTDB]
----
INFO | jvm 1 | 2016/12/23 00:13:48 | Caused by: io.mycat.config.util.ConfigException: SelfCheck### schema scott refered by user scott is not exist!
Caused by: io.mycat.config.util.ConfigException: org.xml.sax.SAXParseException; lineNumber: 63; columnNumber: 16; The value of attribute "name" associated with an element type "schema" must not contain the '<' character.
INFO | jvm 1 | 2016/12/23 00:48:25 | 2016-12-23 00:48:25,238 [DEBUG][Timer0] JDBCHeartBeat con query sql: select 1 from dual (io.mycat.backend.jdbc.JDBCHeartbeat:JDBCHeartbeat.java:109)
INFO | jvm 1 | 2016/12/23 00:48:31 | 2016-12-23 00:48:31,482 [INFO ][$_NIOREACTOR-0-RW] [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=10.0.1.134,port=9066,schema=TESTDB]'system' login success (io.mycat.net.handler.FrontendAuthenticator:FrontendAuthenticator.java:194)
INFO | jvm 1 | 2016/12/23 00:48:31 | 2016-12-23 00:48:31,485 [DEBUG][$_NIOREACTOR-0-RW] [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=10.0.1.134,port=9066,schema=TESTDB] show databases (io.mycat.net.FrontendConnection:FrontendConnection.java:288)
INFO | jvm 1 | 2016/12/23 00:48:31 | 2016-12-23 00:48:31,486 [DEBUG][$_NIOREACTOR-0-RW] [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=10.0.1.134,port=9066,schema=TESTDB]show databases (io.mycat.manager.ManagerQueryHandler:ManagerQueryHandler.java:58)
INFO | jvm 1 | 2016/12/23 00:48:31 | 2016-12-23 00:48:31,501 [DEBUG][$_NIOREACTOR-0-RW] [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=10.0.1.134,port=9066,schema=TESTDB] show tables (io.mycat.net.FrontendConnection:FrontendConnection.java:288)
INFO | jvm 1 | 2016/12/23 00:48:31 | 2016-12-23 00:48:31,502 [DEBUG][$_NIOREACTOR-0-RW] [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=10.0.1.134,port=9066,schema=TESTDB]show tables (io.mycat.manager.ManagerQueryHandler:ManagerQueryHandler.java:58)
INFO | jvm 1 | 2016/12/23 00:48:31 | 2016-12-23 00:48:31,504 [DEBUG][$_NIOREACTOR-0-RW] [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=10.0.1.134,port=9066,schema=TESTDB] select @@version_comment limit 1 (io.mycat.net.FrontendConnection:FrontendConnection.java:288)
INFO | jvm 1 | 2016/12/23 00:48:31 | 2016-12-23 00:48:31,504 [DEBUG][$_NIOREACTOR-0-RW] [thread=$_NIOREACTOR-0-RW,class=ManagerConnection,id=1,host=10.0.1.134,port=9066,schema=TESTDB]select @@version_comment limit 1 (io.mycat.manager.ManagerQueryHandler:ManagerQueryHandler.java:58)
INFO | jvm 1 | 2016/12/23 00:54:03 | 2016-12-23 00:54:03,688 [ERROR][Timer1] JDBCHeartBeat error java.sql.SQLException: Listener refused the connection with the following error:
INFO | jvm 1 | 2016/12/23 00:54:03 | ORA-12505, TNS:listener does not currently know of SID given in connect descriptor
INFO | jvm 1 | 2016/12/23 00:54:03 | The Connection descriptor used by the client was:
INFO | jvm 1 | 2016/12/23 00:54:03 | 10.0.1.103:1521:ORACLEDB
[mysql@hongquan ~]$ mysql -uroot -proot -P9066 -h10.0.1.134 -Dgrs
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.29-mycat-1.6-RELEASE-20161010173036 MyCat Server (monitor)
Copyright (c) 2000, 2013, 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> show @@databases;
+----------+
| DATABASE |
+----------+
| TESTDB |
| grs |
+----------+
2 rows in set (0.00 sec)
mycat接oracle和mysql多个实例的更多相关文章
- Oracle、MySql、SQLServer数据分页查询
看过此博文后Oracle.MySql.SQLServer 数据分页查询,在根据公司的RegionRes表格做出了 SQLserver的分页查询语句: 别名.字段 FROM( SELECT row_nu ...
- ORACLE VS MYSQL
ORACLE VS MYSQL 一.历史 1. Oracle: 中文译作甲骨文,这是一家传奇的公司,有一个传奇的大老板Larry Ellision. Ellision 32岁还一事无成,读了三个大学 ...
- 数据库笔试面试题库(Oracle、MySQL等)
数据库笔试面试题库(Oracle.MySQL等) 版权声明:版权所有,欢迎分享本文,转载请保留出处,否则追究法律责任,谢谢合作. 注:本文将持续更新,可关注作者微信公众号以便获得最新笔试面试资料. ⊙ ...
- 数据库 --> SQL Server 和 Oracle 以及 MySQL 区别
SQL Server 和 Oracle 以及 MySQL 区别 三者是目前市场占有率最高(依安装量而非收入)的关系数据库,而且很有代表性.排行第四的DB2(属IBM公司),与Oracle的定位和架构非 ...
- 事务,Oracle,MySQL及Spring事务隔离级别
一.什么是事务: 事务逻辑上的一组操作,组成这组操作的各个逻辑单元,要么一起成功,要么一起失败. 二.事务特性(4种): 原子性 (atomicity):强调事务的不可分割:一致性 (consiste ...
- mycat实现简单的mysql集群负载均衡
什么是mycat呢? 简单理解为一个MySQL中间件,它支持分流.基于心跳的自动故障切换,支持读写分离,支持mysql主从,基于Nio管理线程的高并发… 详见官网:http://www.mycat.i ...
- Oracle 与 mysql 建立透明网关
1.1.1. 文档编写目的 项目上需要做与Mysql数据库的对接,然而Oracle与Mysql数据库是异构的,因此这里采用透明网关的方式来解决. 另,项目上的环境为APP:12.2.6 ; DB: ...
- [转载]DB2与ORACLE、MYSQL比较2
原文地址:DB2与ORACLE.MYSQL比较2作者:欣颖 4.2 Oracle9i Oracle的产品战略是每12到18个月发布一个主要版本.主要发行版本所遵循的命名战略在PC领域中更为常见,它不 ...
- 从Oracle到MySQL,余额宝云实践分享
原文链接:http://www.csdn.net/article/2013-11-/2817426-interview-financial-case-yuerbao-aliyun07 余额宝.百度百发 ...
随机推荐
- 2015年蓝桥杯C/C++ B组题目题解
1. 输入一个字符串,求它包含多少个单词.单词间以一个或者多个空格分开. 第一个单词前,最后一个单词后也可能有0到多个空格.比如:" abc xyz" 包含两个单词,"a ...
- 吴恩达深度学习笔记(十二)—— Batch Normalization
主要内容: 一.Normalizing activations in a network 二.Fitting Batch Norm in a neural network 三.Why does ...
- ADO.Net连接Oracle
1.添加 Oracle.ManagedDataAccess.dll 2.连接Oracle的实例得添加到Oracle的监听器中,不然会报“ORA-12514: TNS: 监听程序当前无法识别连接描述符中 ...
- 【P2476】着色方案(记忆化搜索+特殊的DP数组)
这个题代码难度几乎为0,然而思维难度对于蒟蒻来说简直是突破天际啊!首先我思考的是这个油漆的种类只有15种,是不是可以像一道叫做8数码难题的东西暴力15维数组呢..计算发现不可以....空间会直接让你学 ...
- SBT搭建Spark
http://www.cnblogs.com/yongjian/p/6211007.html http://www.aboutyun.com/thread-8587-1-1.html http://b ...
- HTTP通信模拟表单提交数据
前面记录过一篇关于http通信,发送数据的文章:http://www.cnblogs.com/hyyq/p/7089040.html,今天要记录的是如何通过http模拟表单提交数据. 一.通过GET请 ...
- JavaScript 对时间日期格式化
JavaScript 对时间日期格式化 // 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位 ...
- 在OSX上安装python3使用pip安装Flask
官方的pypi.python.org可能访问不了,可以先将pip配置为豆瓣的pypi镜像 $ mkdir ~/.pip $ vim ~/.pip/pip.conf [global] timeout = ...
- Hive数据分析——Spark是一种基于rdd(弹性数据集)的内存分布式并行处理框架,比于Hadoop将大量的中间结果写入HDFS,Spark避免了中间结果的持久化
转自:http://blog.csdn.net/wh_springer/article/details/51842496 近十年来,随着Hadoop生态系统的不断完善,Hadoop早已成为大数据事实上 ...
- 17-THREE.JS 光晕滤镜
<!DOCTYPE html> <html> <head> <title></title> <script src="htt ...