Mixer: An Introduction to mysqlproxy implemented with go
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.