Mixer: A mysql proxy implemented with go

Source: Internet
Author: User
Tags mysql commands mysql functions

Introduction

Mixer is a mysql proxy implemented by go and supports basic mysql proxy functions.

Mysql has a lot of middleware. For the existing powerful proxies on the market, I mainly examine the following:

  • Mysql-proxy, an official mysql proxy, is unfriendly to use and requires lua customization. I am also skeptical about its stability and performance.
  • Cobar, Alibaba's stuff, poor quality, but for our project, it's a bit cool, and we don't know java.
  • The mysql-proxy-based enhanced version produced by Atlas and 360 almost overwrites the core framework with c. The performance and stability have nothing to say.

Of course, there are still a lot of powerful proxies that I cannot cover one by one. At this stage, we use Atlas in our project (this does not count as an advertisement for Atlas ?).

Since there are so many proxies, why do I still want to implement one myself? Maybe the main reason is interest.

Mysql Function Support

When I started developing mixer, I knew that mixer is not mysql and cannot proxy all mysql functions. Therefore, I decided that mixer only supports the following mysql commands:

  • COM_QUERY
    • Select, insert, update, delete, replace
    • Set autocommit
    • Set names
    • Begin, commit, rollback
  • COM_PING
  • COM_INIT_DB
  • COM_STMT_PREPARE, COM_STMT_EXEC, and other COM_STMT _ * commands. Only the prepare of the preceding COM_QUERY command is supported.

[Mixer] (https://github.com/siddontang/mixerdoes not support a large number of commands, as shown in the following:

  • Set variable. If supported, mixer needs to maintain the state of each variable, increasing the complexity. However, mixer supports autocommit and names settings.
  • Prepare statement in SQL text mode.
  • Show command.
  • Stored procedure.

Although many functions are not available at this stage, subsequent support is not excluded.

High Availability Solution

Mixer provides a set of high-availability mysql solutions. The main functions at this stage are as follows:

  • Read/write Splitting: Send the select statement to slave and the rest to the master for execution. All the tasks are executed on the master. Currently, only one master node and one slave node are supported.
  • Automatic Master/Slave switchover. When the master mysql is unavailable, it is switched to backup mysql for execution according to relevant rules.
Todo

Mixer is not complete yet, and many functions need to be implemented. The following functions need to be implemented first:

  • Parser, parses the SQL syntax and builds the AST. At the proxy layer, it prevents some mysql risks, such as injection attacks and delete without where.
  • Custom routing: routes SQL statements to different mysql instances according to routing rules. For example, the select statement is hashed to different slave based on the primary key for execution.
  • Statistical function.

The code can be found at https://github.com/siddontang/mixer. I very much hope that the children's shoes who are interested in proxy will join in to improve mixer and make it another mysql middleware solution.

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.