MySQL proxy Working Mechanism Analysis)

Source: Internet
Author: User

Original article: http://www.ningoo.net/html/2008/how_mysql_proxy_works.html

The MySQL proxy is located between the client application and the MySQL server, and implements its function by truncating, changing, and forwarding the communication between the client and the backend database.WinGateThe basic idea of network proxy servers is the same. 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 ProtocolThere are two basic processes: authentication and query:

The authentication process includes:

  1. The client initiates a connection request to the server.
  2. The server sends a handshake message to the client.
  3. The client sends an authentication request to the server.
  4. The server sends the authentication result to the client.

If the authentication succeeds, the query process is displayed:

  1. The client initiates a query request to the server.
  2. 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 proxyLuaScript 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 ()

Why?LuaScript language. I think this is because MySQL proxy usesWormholeThe relationship between storage engines. This plug-in storage engine is very interesting. The data storage format is a Lua script, which is really creative.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.