# tar zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/
# vim /usr/local/mycat/conf/server.xml //添加以下内容 <user name="user"> //mycat用户名 <property name="password">user</property> //mycat密码 <property name="schemas">mytest</property> //mycat虚拟数据库名 <property name="readOnly">true</property> //只读 </user> <user name="tankzhang"> <property name="password">admin</property> <property name="schemas">mytest</property> </user>
# cat schema.xml <?xml version="1.0"?> <!DOCTYPE mycat:schema SYSTEM "schema.dtd"> <mycat:schema xmlns:mycat="http://io.mycat/"> <schema name="mytest" checkSQLschema="false" sqlMaxLimit="100" dataNode="my1" />//定义虚拟数据库名mytest <dataNode name="my1" dataHost="test1" database="test" /> //真实数据库名test <dataHost name="test1" maxCon="1000" minCon="10" balance="1" writeType="0" dbType="mysql" dbDriver="native" > <heartbeat>select user()</heartbeat> <writeHost host="hostM1" url="192.168.5.213:3306" user="tank" password="123456" > //真实数据库的连接方式 <readHost host="hostS1" url="192.168.5.214:3306" user="tank" password="123456" /> //同上 </writeHost> </dataHost> </mycat:schema>
grant all privileges on test.* to tank@"192.168.%" identified by '123456'; flush privileges
# ./mycat start Starting Mycat-server... # netstat -tpnl |grep 8066 tcp 0 0 :::8066 :::* LISTEN 31728/java # ./mycat status Mycat-server is running (31726).
# mysql -u tankzhang -p -P 8066 -h 127.0.0.1 //一定要带上127.0.0.1
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.29-mycat-1.6-RELEASE-20161028204710 MyCat Server (OpenCloundDB)
Copyright (c) 2000, 2016, 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 |
+----------+
| mytest | //虚拟数据库
+----------+
1 row in set (0.00 sec)
mysql> use mytest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
mysql> CREATE TABLE IF NOT EXISTS `user` (
-> `id` int(11) unsigned NOT NULL DEFAULT '0' COMMENT 'ID',
-> `name` varchar(20) NOT NULL DEFAULT '' COMMENT '姓名',
-> `create_time` int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
-> PRIMARY KEY (`id`)
-> ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Query OK, 0 rows affected (0.08 sec)
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| user |
+----------------+
1 row in set (0.01 sec)
mysql> INSERT INTO `user` (`id` ,`name`)VALUES ('1', 'tank');
Query OK, 1 row affected (0.00 sec)
mysql> select * from user; //修改从数据库的user表中的name,会发现读是从从数据库读取的
+----+-----------+-------------+
| id | name | create_time |
+----+-----------+-------------+
| 1 | tankzhang | 0 |
+----+-----------+-------------+
1 row in set (0.01 sec)
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有