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多个实例的更多相关文章

  1. Oracle、MySql、SQLServer数据分页查询

    看过此博文后Oracle.MySql.SQLServer 数据分页查询,在根据公司的RegionRes表格做出了 SQLserver的分页查询语句: 别名.字段 FROM( SELECT row_nu ...

  2. ORACLE VS MYSQL

    ORACLE VS MYSQL 一.历史 1.  Oracle: 中文译作甲骨文,这是一家传奇的公司,有一个传奇的大老板Larry Ellision. Ellision 32岁还一事无成,读了三个大学 ...

  3. 数据库笔试面试题库(Oracle、MySQL等)

    数据库笔试面试题库(Oracle.MySQL等) 版权声明:版权所有,欢迎分享本文,转载请保留出处,否则追究法律责任,谢谢合作. 注:本文将持续更新,可关注作者微信公众号以便获得最新笔试面试资料. ⊙ ...

  4. 数据库 --> SQL Server 和 Oracle 以及 MySQL 区别

    SQL Server 和 Oracle 以及 MySQL 区别 三者是目前市场占有率最高(依安装量而非收入)的关系数据库,而且很有代表性.排行第四的DB2(属IBM公司),与Oracle的定位和架构非 ...

  5. 事务,Oracle,MySQL及Spring事务隔离级别

    一.什么是事务: 事务逻辑上的一组操作,组成这组操作的各个逻辑单元,要么一起成功,要么一起失败. 二.事务特性(4种): 原子性 (atomicity):强调事务的不可分割:一致性 (consiste ...

  6. mycat实现简单的mysql集群负载均衡

    什么是mycat呢? 简单理解为一个MySQL中间件,它支持分流.基于心跳的自动故障切换,支持读写分离,支持mysql主从,基于Nio管理线程的高并发… 详见官网:http://www.mycat.i ...

  7. Oracle 与 mysql 建立透明网关

    1.1.1.   文档编写目的 项目上需要做与Mysql数据库的对接,然而Oracle与Mysql数据库是异构的,因此这里采用透明网关的方式来解决. 另,项目上的环境为APP:12.2.6 ; DB: ...

  8. [转载]DB2与ORACLE、MYSQL比较2

    原文地址:DB2与ORACLE.MYSQL比较2作者:欣颖 4.2 Oracle9i  Oracle的产品战略是每12到18个月发布一个主要版本.主要发行版本所遵循的命名战略在PC领域中更为常见,它不 ...

  9. 从Oracle到MySQL,余额宝云实践分享

    原文链接:http://www.csdn.net/article/2013-11-/2817426-interview-financial-case-yuerbao-aliyun07 余额宝.百度百发 ...

随机推荐

  1. iOS APP AppIcon& LaunchImage

    AppIcon size for iPhone: 29 - Settings @1x 29*29,  58 - Settings @2x 58*58, 87 - Settings @3x 87*87 ...

  2. Hadoop学习1(初识hadoop)

    Hadoop生态系统的特点 1)源代码开源 2)社区活跃,参与者多 3)涉及分布式存储和计算的各方面 4)已得到企业界的验证 Hadoop构成 1) 分布式文件系统HDFS(Hadoop Distri ...

  3. C#二进制与字符串互转换,十六进制转换为字符串、float、int

    /// <summary>     /// 将 字符串 转成 二进制 “10011100000000011100011111111101” /// </summary> /// ...

  4. Mysql5.7压缩版安装启动不了的问题

    从mysql 官网下载了mysql-5.7.12-winx64.zip的文件.按步骤安装: 1.添加环境变量     操作如下:     1)右键单击我的电脑->属性->高级系统设置(高级 ...

  5. 我总结的call()与apply()方法的区别

    [call()与apply()的区别]在ECMAScript中每一个函数都是function类型(是javascript的基本引用类型)的实例,具有一定的属性和方法.call()和apply()则是这 ...

  6. Sublime Text3取消自动补全结束标签

    点击首选项——设置-用户——在配置中增加一句:"auto_close_tags": false, 参考来源:豆瓣小组:求解Sublime Text 3怎么取消自动补全结束标签

  7. 太深了,梯度传不下去,于是有了highway。 干脆连highway的参数都不要,直接变残差,于是有了ResNet。 强行稳定参数的均值和方差,于是有了BatchNorm。RNN梯度不稳定,于是加几个通路和门控,于是有了LSTM。 LSTM简化一下,有了GRU。

    请简述神经网络的发展史sigmoid会饱和,造成梯度消失.于是有了ReLU.ReLU负半轴是死区,造成梯度变0.于是有了LeakyReLU,PReLU.强调梯度和权值分布的稳定性,由此有了ELU,以及 ...

  8. vue自定义全局组件(自定义插件)

    有时候我们在做开发的时候,就想自己写一个插件然后就可以使用自己的插件,那种成就感很强.博主最近研究element-ui和axios的时候,发现他们是自定义组件,但是唯一有一点不同的是,在用elemen ...

  9. MySQL分片 --转自Peter Zaitsev对MySQL分片的建议

    本文作者Peter Zaitsev是知名数据库专家,2006年联合创立了Percona.负责维护网站“MySQL性能”.同时,他也是<高性能MySQL>一书的联合作者.以下是他对MySQL ...

  10. MariaDB Galera Cluster环境搭建及高可用测试

    一.服务器概况Galera Cluster需要至少三个节点,在此次实验过程中,三个节点IP地址:192.168.56.101192.168.56.102192.168.56.103OS为centos ...