zoukankan      html  css  js  c++  java
  • mycat读写分离

    mycat读写分离

    1.schema.xml配置文件

    <?xml version="1.0"?>
    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
    <mycat:schema xmlns:mycat="http://io.mycat/">
    	<schema name="khtdb" checkSQLschema="true" sqlMaxLimit="100" dataNode="dn1">
    	</schema>
    	<dataNode name="dn1" dataHost="host1" database="khtdb" />
    	<dataHost name="host1" maxCon="1000" minCon="10" balance="2"
    			  writeType="0" dbType="mysql" dbDriver="native" switchType="1"  slaveThreshold="100">
    		<heartbeat>select user()</heartbeat>
        <writeHost host="hostM1" url="192.168.2.128:3306" user="root"
    				   password="kht123">
    		<readHost host="hostS1" url="192.168.2.129:3306" user="root" password="kht123" />
        </writeHost>
    	</dataHost>
    </mycat:schema>
    
    <?xml version="1.0"?>
    <!DOCTYPE mycat:schema SYSTEM "schema.dtd">
    <mycat:schema xmlns:mycat="http://io.mycat/">
    	<schema name="khtdb" checkSQLschema="true" sqlMaxLimit="100" randomDataNode="dn1" dataNode="dn1">
    	</schema>
    	<dataNode name="dn1" dataHost="host1" database="khtdb" />
    	<dataHost name="host1" maxCon="1000" minCon="10" balance="0"
    			  writeType="0" dbType="mysql" dbDriver="jdbc" switchType="1"  slaveThreshold="100">
    		<heartbeat>select user()</heartbeat>
    		<writeHost host="hostM1" url="jdbc:mysql://192.168.2.130:3306" user="root"
    				   password="kht123">
    			<readHost host="hostS1" url="jdbc:mysql://192.168.2.131:3306" user="root" password="kht123" />
    		</writeHost>
    	</dataHost>
    </mycat:schema>
    

    2.server.xml配置文件修改点

    	<user name="mycat" defaultAccount="true">
    		<property name="password">123456</property>
    		<property name="schemas">khtdb</property>
    		<!-- 表级 DML 权限设置 -->
    		<!-- 		
    		<privileges check="false">
    			<schema name="TESTDB" dml="0110" >
    				<table name="tb01" dml="0000"></table>
    				<table name="tb02" dml="1111"></table>
    			</schema>
    		</privileges>		
    		 -->
    	</user>
    

    3.若报错“ ERROR 3009 (HY000): Java.lang.IllegalArgumentException: Invalid DataSource:0 错误”

    登录mysql后修改ROOT用户,update user set host = '%' where user = 'root'; 重启mysql服务
    mycat登录命令:mysql -umycat -p123456 -P 8066 -h 192.168.2.128
    在写主机数据库表mytbl中插入带系统变量数据,造成主从数据不一致
    INSERT INTO mytbl VALUES(2,@@hostname);
    
  • 相关阅读:
    人月神话阅读笔记01
    第二周总结
    第一周总结
    软件工程课程总结
    FIR滤波器窗函数设计法详细步骤以及Matlab代码
    【转载】傅立叶变换、拉普拉斯变换、Z变换之间的联系?
    Matlab实现IIR数字滤波器设计
    数字信号滤波器的重要函数
    奇异谱分析
    字符串解码DecodeString
  • 原文地址:https://www.cnblogs.com/khtt/p/15211752.html
Copyright © 2011-2022 走看看