天天看点

【原创】MySQL Proxy - 协议(部分摘录)

【generic response packets】->【status flags】 

the status flags are a bit-field: 

======     ============= ======== 

   flag               constant name 

0x0001         server_status_in_trans 

0x0002         server_status_autocommit 

0x0008         _`server_more_results_exists` 

0x0010         server_status_no_good_index_used 

0x0020         server_status_no_index_used 

0x0040         server_status_cursor_exists 

0x0080         server_status_last_row_sent 

0x0100         server_status_db_dropped 

0x0200         server_status_no_backslash_escapes 

0x0400         server_status_metadata_changed 

0x0800         server_query_was_slow 

0x1000         server_ps_out_params 

======       ============= ======== 

       the capability flags are used by the client and server to indicate which features    they support and want to use.   

【auth challenge packet】->【capability flags】 

====== =======================  ======================== 

    flags                 constant name                                    description 

0x0001          client_long_password           new more secure passwords 

0x0002           client_found_rows                 found instead of affected rows 

0x0004           client_long_flag                     get all column flags 

0x0008           client_connect_with_db       one can specify db on connect 

0x0010           client_no_schema                   don't allow database.table.column 

0x0020           client_compress                      can use compression protocol 

0x0040           client_odbc                               odbc client 

0x0080           _`client_local_files`                can use load data local 

0x0100           client_ignore_space               ignore spaces before '(' 

0x0200           _`client_protocol_41`             new 4.1 protocol 

0x0400           client_interactive                   this is an interactive client 

0x0800           client_ssl                                   switch to ssl after handshake 

0x1000           client_ignore_sigpipe             ignore sigpipes 

0x2000           client_transactions             client knows about transactions 

0x4000           client_reserved                       old flag for 4.1 protocol  

0x8000           client_secure_connection   new 4.1 authentication 

【auth response packet】->【 capability flags 】 

`capability flags` are the same as defined in the `capability flags`_ of the `auth challenge packet`_ plus: 

====== =======================  ========================  

====== =======================  ========================    

0x00010000    _`client_multi_statements`      enable/disable multi-stmt support 

0x00020000    _`client_multi_results`              enable/disable multi-results 

0x00040000    _`client_ps_multi_results`         multi-results in ps-protocol 

0x40000000    client_ssl_verify_server_cert 

0x80000000    client_remember_options 

【 command-type】 

the first byte of the payload describes the command-type like: 

=== ===================  ========================  

hex           constant name                                      description  

00       `com_sleep`_                        unhandled 

01       `com_quit`_                         tells the server that the client wants to close the connection 

02       `com_init_db`_                    change the default schema of the connection 

03       `com_query`_                      tells the server to execute a text-based query 

04       `com_field_list`_                get the column definition of a tables 

05       `com_create_db`_              create a schema 

06       `com_drop_db`_                 drop a schema 

07       `com_refresh`_                  get a list of active threads 

08       `com_shutdown`_            get a list of active threads 

09       `com_statistics`_               get a list of active threads 

0a       `com_process_info`_        get a list of active threads 

0b       `com_connect`_                unhandled 

0c       `com_process_kill`_          ask the server to terminate a connection 

0d      `com_debug`_                      dump debug info to stdout 

0e       `com_ping`_                         check if the server is alive 

0f        `com_time`_                         unhandled 

10       `com_delayed_insert`_    unhandled 

11       `com_change_user`_        change the user of the current connection 

12        com_binlog_dump          (null) 

13       `com_table_dump`_          unhandled 

14       `com_connect_out`_        unhandled 

15        com_register_slave        (null) 

16       `com_stmt_prepare`_       creates a prepared statement from the passed query string. 

17       `com_stmt_execute`_      asks the server to execute a prepared statement as identified by `stmt-id`. 

18       `com_stmt_send_long_data`_    sends the data for a column. repeating to send it, appends the data to the parameter. 

19       `com_stmt_close`_         deallocates a prepared statement. 

1a       `com_stmt_reset`_         resets the data of a prepared statement. useful in together with `com_stmt_send_long_data`_. 

1b       `com_set_option`_         set options for the current connection 

1c       `com_stmt_fetch`_         (null)  

1d      `com_daemon`_               unhandled 

=== ===================  ======================== 

the unhandled   commands belong to  

* the `old commands`_ 

* the `prepared statements`_ commands 

* the `stored procedures`_ commands 

* or the replication commands