Analysis on the working mechanism of Lua Script: MySQL Proxy

Source: Internet
Author: User

MySQL ProxyIt is between the client application and the MySQL server and implements its function by truncating, changing, and forwarding communications 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.MySQL ProxyThe working mechanism should also be clearMySQLCommunication protocol between the client and the server,MySQLProtocol 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 ProxyUse 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:

 
 
  1. connect_server()   
  2. read_handshake()   
  3. read_auth()   
  4. read_auth_result()   
  5. read_query()   
  6. read_query_result()  

As for why the lua scripting 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 isLua scriptIt's really creative.

Summary:MySQL Proxy Lua scriptThe work mechanism analysis is complete. I hope this article will help you.

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.