1. What is mycat A completely open source large database cluster for enterprise application development An enhanced database that supports transactions, ACID, and can replace MySQL An enterprise-class database that can be viewed as a MySQL cluster to replace expensive Oracle clusters A new SQL Server that integrates memory cache technology, NoSQL technology, and HDFS big data A new generation of enterprise-level database products that combines traditional databases with new distributed data warehouses A novel database middleware product The above is the official statement. In fact, it is the database connection pool. MySQL proxy is also a connection pool, but its efficiency is very low. 2. Mycat installation 1. Download mycat 2. Install mycat # tar zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/ 3. Configure mycat 1. Configure server.xml # vim /usr/local/mycat/conf/server.xml //Add the following content<user name="user"> //mycat user name<property name="password">user</property> //mycat password<property name="schemas">mytest</property> //mycat virtual database name<property name="readOnly">true</property> //Read-only</user> <user name="tankzhang"> <property name="password">admin</property> <property name="schemas">mytest</property> </user> Please note that the default virtual database name is TESTDB. If testdb is not configured in schema.xml, you need to change testdb to the virtual database name in schema.xml. The username and password, and virtual database name defined here do not actually exist in MySQL. 2. Configure schema.xml # 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" />//Define the virtual database name mytest <dataNode name="my1" dataHost="test1" database="test" /> //The real database name is 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" > //Real database connection method <readHost host="hostS1" url="192.168.5.214:3306" user="tank" password="123456" /> //Same as above</writeHost> </dataHost> </mycat:schema> There are quite a lot of mycat configuration parameters. Focus on balance="1" and writeType="0" a. balance attribute load balancing type, currently there are 4 values:
b. writeType attribute Load balancing type. Currently there are 3 values:
Specific parameters 3. Configure the master-slave server 4. Add real users grant all privileges on test.* to tank@"192.168.%" identified by '123456'; flush privileges Add users on machines 213 and 214. 5. Test real user connection Make sure that the real user configured in schema.xml can connect to the real database. Be aware of firewalls. Fourth, start mycat 1. Common parameters ./mycat start Start./mycat stop Stop./mycat console Run in the foreground./mycat restart Restart the service./mycat pause Pause./mycat status Check the startup status 2. Start and view mycat # ./mycat start Starting Mycat-server... # netstat -tpnl |grep 8066 tcp 0 0 :::8066 :::* LISTEN 31728/java # ./mycat status Mycat-server is running (31726). 5. Test read-write separation # mysql -u tankzhang -p -P 8066 -h 127.0.0.1 //Be sure to include 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 | //Virtual database+----------+ 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 'Name', -> `create_time` int(10) NOT NULL DEFAULT '0' COMMENT 'Creation time', -> 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; //Modify the name in the user table of the slave database, and you will find that the read is read from the slave database +----+-----------+-------------+ | id | name | create_time | +----+-----------+-------------+ | 1 | tankzhang | 0 | +----+-----------+-------------+ 1 row in set (0.01 sec) VI. Summary mycat supports mysql table partitioning, sharding, etc., but it is not recommended. Mycat does not support many clusters, so it would be great if it could be used with mha. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: A simple example of using Vue3 routing VueRouter4
>>: Detailed configuration steps for installing Linux (CentOS) under VMware virtual machine
This article example shares the specific code for...
<br />Based on the original width-and-height...
Table of contents JSON appears Json structure Jso...
Base image The base image has two meanings: Does ...
Mysql query time period intersection Usage scenar...
Sometimes you need to install certain dependencie...
1. Download the download link Click download. You...
Docker Features 1) Quick to get started It only t...
How long has it been since I updated my column? H...
This article shares with you the graphic tutorial...
Table of contents 1. Background 2. Operation step...
As the title says: The height is known, the width...
1. Zabbix backup [root@iZ2zeapnvuohe8p14289u6Z /]...
I believe some people have seen this picture of c...
In this article, I will show you how to install a...