We all know that MySQL Proxy is between the actual application of the client and the MySQL database server. It is mainly implemented by truncation, changing, and forwarding the communication between the client and the backend database, this is the same as the basic idea of network proxy servers such as WinGate.
The Proxy server deals with the TCP/IP protocol. To understand the working mechanism of the MySQL Proxy, you must also understand the communication protocol between the MySQL client and the server, mySQL Protocol includes two basic processes: authentication and query:
The authentication process includes:
The client initiates a connection request to the server.
The server sends a handshake message to the client.
The client sends an authentication request to the server.
The server sends the authentication result to the client.
If the authentication succeeds, the query process is displayed:
The client initiates a query request to the server.
The server returns the query result to the client.
Of course, this is just a rough description. The packages sent in each process are in a fixed format. If you want to learn more about MySQL Protocol, please go here. What MySQL Proxy needs to do is to intervene in various processes of the Protocol. First, MySQL Proxy accepts client requests as the server, analyzes and processes these requests according to the configuration, and then forwards the requests to the corresponding backend database server as the client, and then accepts the server information, return to the client.
Therefore, MySQL Proxy must implement both the client and server protocols. To analyze the SQL statements sent from the client, you also need to include an SQL parser. MySQL Proxy is equivalent to a lightweight MySQL. In fact, the admin server of MySQL Proxy can use SQL to query status information.
MySQL Proxy uses the lua script to control the connection forwarding mechanism. The main functions are used in various MySQL Protocol processes. This can be seen from the function name:
- connect_server()
- read_handshake()
- read_auth()
- read_auth_result()
- read_query()
- read_query_result()
As for why the lua script language is used, I think this is because the wormhole storage engine is used in MySQL Proxy. This worm hole storage engine is very interesting. The data storage format is a lua script, it's really creative.
MySQL Server Load balancer written by Chinese people
The following is an introduction to amoeba:
Amoeba is located between Client and Database Server (s. With load balancing, high availability, SQL filtering, high concurrency, read/write splitting, Query Route parsing SQL query statements, and according to the conditions and preset rules, request to the specified target database. Can concurrently request the merge results of multiple databases), transparent to the client.
It mainly reduces the impact of complex multi-database structures and data splitting rules on applications caused by data splitting.
Easy read/write splitting
Failover
Server Load balancer.
Able to help solve data splitting problems
Currently, amoeba implements MySQL database-related technologies.
Applicable:
MySQL 4.1 or later MySQL Protocol Version: 10)
Currently, transactions and DDL statements are not supported and are only allocated to the default database for execution.
Running environment:
At least one MySQL 4.1 Service must be run;
Java 1.5 or later
The above content is an introduction to MySQL proxy read/write splitting. I hope you will have some gains.