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>

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);

mycat读写分离

上一篇:计算火车运行时间(PTA)


下一篇:Photoshop制作I MISS YOU黄绿色签名