Home Database Mysql Tutorial Detailed explanation on the installation and use of mycat middleware for mysql

Detailed explanation on the installation and use of mycat middleware for mysql

May 28, 2017 am 09:49 AM

MyCAT is MySQLmiddleware, formerly known as Alibaba's famous Cobar. After Cobar was open sourced for a period of time, it stopped. So MyCAT took up this banner, and in the era of big data, its importance has become increasingly apparent. This article is mainly about the introductory deployment of MyCAT.

1. What is mycat

A completely open source, large database cluster for enterprise application development

Supports transactions, ACID, and can replace MySQL An enhanced version of the database

An enterprise-level database that can be regarded as a MySQL cluster to replace the expensive Oracle cluster

A fusion memorycachingtechnology, NoSQL technology, HDFS The new SQL Server for big data

A new generation of enterprise-level database product that combines traditional databases and new distributed data warehouses

A novel database middleware product

The above is official illustrate. In fact, it is the connection pool of the database. Mysql proxy is also a connection pool, but its efficiency is very low.

Second, mycat installation

1, download address mycat

2, install mycat

# tar zxvf Mycat-server-1.6-RELEASE-20161028204710-linux.tar.gz -C /usr/local/
Copy after login

Three, configure mycat

1, configure server.xml

# 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>
Copy after login

It should be noted here that the default virtual data name is TESTDB , if testdb is not configured in schema.xml, then testdb must be changed to the virtual data name in schema.xml. The username, 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" />//定义虚拟数据库名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>
Copy after login

There are quite a lot of configuration parameters for mycat. Focus on balance="1" and writeType="0"

a. balance AttributeLoad balancing type, there are currently 4 values:

1. balance="0", the read-write separation mechanism is not enabled, and all read operations are sent to the currently available writeHost.

2. balance="1", all readHost and stand by writeHost participate in the load balancing of the select statement. Simply put, when the dual master dual slave mode (M1 ->S1, M2->S2 , and M1 and M2 are mutually active and backup). Under normal circumstances, M2, S1, and S2 all participate in the load balancing of the select statement.

3. balance="2", all read operations are randomly distributed on writeHost and readhost.

4. balance="3", all read requests are randomly distributed to the readhost corresponding to writerHost for execution. writerHost does not bear the reading pressure. Note that balance=3 is only available in 1.4 and later versions, not 1.3.

b. writeType attribute

Load balancing type, there are currently 3 values:

1. writeType="0", all write operations are sent to the configured first For a writeHost, the first one hangs and is switched to the second

writeHost that is still alive. The one that has been switched after restarting shall prevail. The switching is recorded in the config file: dnindex. properties .

2. writeType="1", all write operations are randomly sent to the configured writeHost.

3. writeType="2", not implemented.

Specific parameters: http://mycat.io/document/Mycat_V1.6.0.pdf

3, configure the master-slave server, I won’t talk about it here, blog There are

4 in it, add real user

grant all privileges on test.* to tank@"192.168.%" identified by &#39;123456&#39;;
flush privileges
Copy after login

Add user on two machines 213 and 214.

5. Test the real user connection to ensure that the real user configured in schema.xml can connect to the real database. Pay attention to firewalls.

Four, 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 View startup status

2, start , and check out mycat

# ./mycat start
Starting Mycat-server...

# netstat -tpnl |grep 8066
tcp 0 0 :::8066 :::* LISTEN 31728/java 

# ./mycat status
Mycat-server is running (31726).
Copy after login

Five, test read and write separation

# 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 &#39;help;&#39; or &#39;\h&#39; for help. Type &#39;\c&#39; 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 &#39;0&#39; COMMENT &#39;ID&#39;,
 -> `name` varchar(20) NOT NULL DEFAULT &#39;&#39; COMMENT &#39;姓名&#39;,
 -> `create_time` int(10) NOT NULL DEFAULT &#39;0&#39; COMMENT &#39;创建时间&#39;,
 -> 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 (&#39;1&#39;, &#39;tank&#39;);
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)
Copy after login

Six, summary

mycat supports mysql points Tables, shards, etc., but their use is not recommended. Mycat does not support many clusters. It would be awesome if it can be used with mha.

The above is the detailed content of Detailed explanation on the installation and use of mycat middleware for mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1658
14
PHP Tutorial
1257
29
C# Tutorial
1231
24
MySQL's Role: Databases in Web Applications MySQL's Role: Databases in Web Applications Apr 17, 2025 am 12:23 AM

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

How to start mysql by docker How to start mysql by docker Apr 15, 2025 pm 12:09 PM

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

Laravel Introduction Example Laravel Introduction Example Apr 18, 2025 pm 12:45 PM

Laravel is a PHP framework for easy building of web applications. It provides a range of powerful features including: Installation: Install the Laravel CLI globally with Composer and create applications in the project directory. Routing: Define the relationship between the URL and the handler in routes/web.php. View: Create a view in resources/views to render the application's interface. Database Integration: Provides out-of-the-box integration with databases such as MySQL and uses migration to create and modify tables. Model and Controller: The model represents the database entity and the controller processes HTTP requests.

Solve database connection problem: a practical case of using minii/db library Solve database connection problem: a practical case of using minii/db library Apr 18, 2025 am 07:09 AM

I encountered a tricky problem when developing a small application: the need to quickly integrate a lightweight database operation library. After trying multiple libraries, I found that they either have too much functionality or are not very compatible. Eventually, I found minii/db, a simplified version based on Yii2 that solved my problem perfectly.

MySQL and phpMyAdmin: Core Features and Functions MySQL and phpMyAdmin: Core Features and Functions Apr 22, 2025 am 12:12 AM

MySQL and phpMyAdmin are powerful database management tools. 1) MySQL is used to create databases and tables, and to execute DML and SQL queries. 2) phpMyAdmin provides an intuitive interface for database management, table structure management, data operations and user permission management.

MySQL vs. Other Programming Languages: A Comparison MySQL vs. Other Programming Languages: A Comparison Apr 19, 2025 am 12:22 AM

Compared with other programming languages, MySQL is mainly used to store and manage data, while other languages ​​such as Python, Java, and C are used for logical processing and application development. MySQL is known for its high performance, scalability and cross-platform support, suitable for data management needs, while other languages ​​have advantages in their respective fields such as data analytics, enterprise applications, and system programming.

Laravel framework installation method Laravel framework installation method Apr 18, 2025 pm 12:54 PM

Article summary: This article provides detailed step-by-step instructions to guide readers on how to easily install the Laravel framework. Laravel is a powerful PHP framework that speeds up the development process of web applications. This tutorial covers the installation process from system requirements to configuring databases and setting up routing. By following these steps, readers can quickly and efficiently lay a solid foundation for their Laravel project.

MySQL vs. Other Databases: Comparing the Options MySQL vs. Other Databases: Comparing the Options Apr 15, 2025 am 12:08 AM

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

See all articles