Proxy Trace Revisited with MySQL Proxy 0.8.2

Back in January 2010, I wrote an article titled Proxy Trace : Tracing the Variables and Functions Available within MySQL Proxy.

That post was basically a lua script I posted which traces the steps of Proxy, outputting comments as it traverses through the various functions, and then outputs the names and values of [most of] the available variables available within Proxy.

That script worked fine with Proxy 0.7.2 and 0.8.0. It also works just fine with Proxy 0.8.1 (though you need to specify your admin settings in 0.8.1) and 0.8.2 (admin values not necessary).

However, I did go ahead and build it out a little further.

I did not add too much, but I did add the following (the full script, trace.lua, is provided at the end of this post):

  • Outputs backends.type variable
  • Expanded the rows returned outputs (returns more detailed row information)
  • Enhanced error reporting
  • Outputs 70 internal constants that Proxy tracks (Server Commands, Types, Backend State, Packet State, and Return State codes)

I still only start the proxy with the following command:

mysql-proxy --proxy-lua-script=trace.lua

And then in my client, I simply connect, issue 1 query, and exit:

shell> mysql -uroot -pmysql -P4040
mysql> select * from world.city where countrycode='usa' limit 3;
mysql> exit

And here is the new trace.lua output from this session:

C:\Program Files\MySQL\mysql-proxy-0.8.2\bin>mysql-proxy --proxy-lua-script=trace.lua
/* Entering function connect_server() */
   When the proxy accepts a connection from a MySQL client, the
   connect_server() function is called.  There are no arguments
   to the function, but you can use and if necessary manipulate
   the information in the proxy.connection table, which is unique
   to each client session.

   INTERNAL CONSTANTS:

   //Proxy Return State Constants:
   proxy.PROXY_SEND_QUERY                       = 1
   proxy.PROXY_SEND_RESULT                      = 2
   proxy.PROXY_IGNORE_RESULT                    = 4

   //Packet State Constants:
   proxy.MYSQLD_PACKET_OK                       = 0
   proxy.MYSQLD_PACKET_ERR                      = 255
   proxy.MYSQLD_PACKET_RAW                      = 250

   //Backend State/Type Constants:
   proxy.BACKEND_STATE_UNKNOWN                  = 0
   proxy.BACKEND_STATE_UP                       = 1
   proxy.BACKEND_STATE_DOWN                     = 2
   proxy.BACKEND_TYPE_UNKNOWN                   = 0
   proxy.BACKEND_TYPE_RW                        = 1
   proxy.BACKEND_TYPE_RO                        = 2

   //Server Command Constants:
   proxy.COM_SLEEP                              = 0
   proxy.COM_QUIT                               = 1
   proxy.COM_INIT_DB                            = 2
   proxy.COM_QUERY                              = 3
   proxy.COM_FIELD_LIST                         = 4
   proxy.COM_CREATE_DB                          = 5
   proxy.COM_DROP_DB                            = 6
   proxy.COM_REFRESH                            = 7
   proxy.COM_SHUTDOWN                           = 8
   proxy.COM_STATISTICS                         = 9
   proxy.COM_PROCESS_INFO                       = 10
   proxy.COM_CONNECT                            = 11
   proxy.COM_PROCESS_KILL                       = 12
   proxy.COM_DEBUG                              = 13
   proxy.COM_PING                               = 14
   proxy.COM_TIME                               = 15
   proxy.COM_DELAYED_INSERT                     = 16
   proxy.COM_CHANGE_USER                        = 17
   proxy.COM_BINLOG_DUMP                        = 18
   proxy.COM_TABLE_DUMP                         = 19
   proxy.COM_CONNECT_OUT                        = 20
   proxy.COM_REGISTER_SLAVE                     = 21
   proxy.COM_STMT_PREPARE                       = 22
   proxy.COM_STMT_EXECUTE                       = 23
   proxy.COM_STMT_SEND_LONG_DATA                = 24
   proxy.COM_STMT_CLOSE                         = 25
   proxy.COM_STMT_RESET                         = 26
   proxy.COM_SET_OPTION                         = 27
   proxy.COM_STMT_FETCH                         = 28
   proxy.COM_DAEMON                             = 29

   //MySQL Type Constants:
   proxy.MYSQL_TYPE_DECIMAL                     = 0
   proxy.MYSQL_TYPE_NEWDECIMAL                  = 246
   proxy.MYSQL_TYPE_TINY                        = 1
   proxy.MYSQL_TYPE_SHORT                       = 2
   proxy.MYSQL_TYPE_LONG                        = 3
   proxy.MYSQL_TYPE_FLOAT                       = 4
   proxy.MYSQL_TYPE_DOUBLE                      = 5
   proxy.MYSQL_TYPE_NULL                        = 6
   proxy.MYSQL_TYPE_TIMESTAMP                   = 7
   proxy.MYSQL_TYPE_LONGLONG                    = 8
   proxy.MYSQL_TYPE_INT24                       = 9
   proxy.MYSQL_TYPE_DATE                        = 10
   proxy.MYSQL_TYPE_TIME                        = 11
   proxy.MYSQL_TYPE_DATETIME                    = 12
   proxy.MYSQL_TYPE_YEAR                        = 13
   proxy.MYSQL_TYPE_NEWDATE                     = 14
   proxy.MYSQL_TYPE_ENUM                        = 247
   proxy.MYSQL_TYPE_SET                         = 248
   proxy.MYSQL_TYPE_TINY_BLOB                   = 249
   proxy.MYSQL_TYPE_MEDIUM_BLOB                 = 250
   proxy.MYSQL_TYPE_LONG_BLOB                   = 251
   proxy.MYSQL_TYPE_BLOB                        = 252
   proxy.MYSQL_TYPE_VAR_STRING                  = 253
   proxy.MYSQL_TYPE_STRING                      = 254
   proxy.MYSQL_TYPE_TINY                        = 1
   proxy.MYSQL_TYPE_ENUM                        = 247
   proxy.MYSQL_TYPE_GEOMETRY                    = 255
   proxy.MYSQL_TYPE_BIT                         = 16

/* Entering function read_handshake() */
   Handshake information is sent by the server to the client
   after the initial connection (through connect_server()) has
   been made.  read_handshake() doesn't receive a parameter
   anymore. Instead all the data is available in the connection
   tables.

/* Entering function read_auth() */
   The read_auth() function is triggered when an authentication
   handshake is initiated by the client.  read_auth() doesn't
   receive a parameter anymore. Instead all the data is
   available in the connection tables.

/* Entering function read_auth_result() */
   The return packet from the server during authentication is
   captured by read_auth_result().

/* Entering function read_query( packet ) */
| o = [backends] userdata: 019136F8 (type=userdata)
[config] table: 01CAE2C0 (type=table)

| Query               = select @@version_comment limit 1
| Time Stamp          = 2011-11-01 19:09:22
| Proxy Version       = 00802
| Lua Version         = Lua 5.1

/* Entering function read_query_result( inj ) */
| os.date                                      = 2011-11-01 19:09:22
| inj.query                                    = ♥select @@version_comment limit 1
| proxy.connection.server.scramble_buffer      = "^PVA!!\"$0d(8#Cg]zrK^"
| proxy.connection.server.mysqld_version       = 50091
| proxy.connection.server.thread_id            = 8
| proxy.connection.client.default_db           =
| proxy.connection.client.username             = root
| proxy.connection.client.scrambled_password   = "╣\\ª≡½bj¼c¬_╫i♫>5úN╡S"
| proxy.connection.client.dst.name             = 127.0.0.1:4040
| proxy.connection.client.dst.address          = 127.0.0.1
| proxy.connection.client.dst.port             = 4040
| proxy.connection.server.dst.name             = 127.0.0.1:3306
| proxy.connection.server.dst.address          = 127.0.0.1
| proxy.connection.server.dst.port             = 3306
| proxy.connection.client.src.name             = 127.0.0.1:50404
| proxy.connection.client.src.address          = 127.0.0.1
| proxy.connection.client.src.port             = 50404
| proxy.connection.server.src.name             = 127.0.0.1:50405
| proxy.connection.server.src.address          = 127.0.0.1
| proxy.connection.server.src.port             = 50405
| inj.query-time                               = 8.366ms
| inj.response-time                            = 8.381ms
| proxy.connection.backend_ndx                 = 1
| #proxy.global.backends                       = 1
| proxy.global.backends[ndx].dst.name          = 127.0.0.1:3306
| proxy.global.backends[ndx].dst.address       = 127.0.0.1
| proxy.global.backends[ndx].dst.port          = 3306
| proxy.global.backends[ndx].connected_clients = 1
| proxy.global.backends[ndx].state             = 1
| proxy.global.backends[ndx].type              = 1
| proxy.global.backends[ndx].pool.max_idle_connections = 0
| proxy.global.backends[ndx].pool.min_idle_connections = 0
| proxy.global.backends[ndx].pool.users[1]     = 0
| result.len                                   = 1
| result.flags.in_trans                        = false
| result.flags.auto_commit                     = true
| result.flags.no_good_index_used              = false
| result.flags.no_index_used                   = false
| result.flags.cursor_exists                   = nil
| result.flags.last_row_sent                   = nil
| result.flags.db_dropped                      = nil
| result.flags.no_backslash_escapes            = nil
| result.flags.metadata_changed                = nil
| result.warning_count                         = 0
| result.query_status                          = 0
| result.fields[1].type                        = 253
| result.fields[1].name                        = @@version_comment
1       MySQL Enterprise Server - Pro Edition (GPL)
| row_count                                    = 1

/* Entering function read_query( packet ) */
| o = [backends] userdata: 019136F8 (type=userdata)
[config] table: 01CAE2C0 (type=table)

| Query               = select * from world.city where countrycode='usa' limit 3
| Time Stamp          = 2011-11-01 19:09:24
| Proxy Version       = 00802
| Lua Version         = Lua 5.1

/* Entering function read_query_result( inj ) */
| os.date                                      = 2011-11-01 19:09:24
| inj.query                                    = ♥select * from world.city where countrycode='usa' limit 3
| proxy.connection.server.scramble_buffer      = "^PVA!!\"$0d(8#Cg]zrK^"
| proxy.connection.server.mysqld_version       = 50091
| proxy.connection.server.thread_id            = 8
| proxy.connection.client.default_db           =
| proxy.connection.client.username             = root
| proxy.connection.client.scrambled_password   = "╣\\ª≡½bj¼c¬_╫i♫>5úN╡S"
| proxy.connection.client.dst.name             = 127.0.0.1:4040
| proxy.connection.client.dst.address          = 127.0.0.1
| proxy.connection.client.dst.port             = 4040
| proxy.connection.server.dst.name             = 127.0.0.1:3306
| proxy.connection.server.dst.address          = 127.0.0.1
| proxy.connection.server.dst.port             = 3306
| proxy.connection.client.src.name             = 127.0.0.1:50404
| proxy.connection.client.src.address          = 127.0.0.1
| proxy.connection.client.src.port             = 50404
| proxy.connection.server.src.name             = 127.0.0.1:50405
| proxy.connection.server.src.address          = 127.0.0.1
| proxy.connection.server.src.port             = 50405
| inj.query-time                               = 8.706ms
| inj.response-time                            = 8.729ms
| proxy.connection.backend_ndx                 = 1
| #proxy.global.backends                       = 1
| proxy.global.backends[ndx].dst.name          = 127.0.0.1:3306
| proxy.global.backends[ndx].dst.address       = 127.0.0.1
| proxy.global.backends[ndx].dst.port          = 3306
| proxy.global.backends[ndx].connected_clients = 1
| proxy.global.backends[ndx].state             = 1
| proxy.global.backends[ndx].type              = 1
| proxy.global.backends[ndx].pool.max_idle_connections = 0
| proxy.global.backends[ndx].pool.min_idle_connections = 0
| proxy.global.backends[ndx].pool.users[1]     = 0
| result.len                                   = 1
| result.flags.in_trans                        = false
| result.flags.auto_commit                     = true
| result.flags.no_good_index_used              = false
| result.flags.no_index_used                   = true
| result.flags.cursor_exists                   = nil
| result.flags.last_row_sent                   = nil
| result.flags.db_dropped                      = nil
| result.flags.no_backslash_escapes            = nil
| result.flags.metadata_changed                = nil
| result.warning_count                         = 0
| result.query_status                          = 0
| result.fields[1].type                        = 3
| result.fields[1].name                        = ID
1       3793
2       New York
3       USA
4       New York
5       8008278
1       3794
2       Los Angeles
3       USA
4       California
5       3694820
1       3795
2       Chicago
3       USA
4       Illinois
5       2896016
| row_count                                    = 3

/* Entering function read_query( packet ) */
| o = [backends] userdata: 019136F8 (type=userdata)
[config] table: 01CAE2C0 (type=table)

/* Entering function disconnect_client() */
Client 8 has disconnected.

Here is the client session for completeness (and perhaps some one may find it useful):

C:\Users\Chris>mysql -uroot -pmysql -P4040
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.0.91-enterprise-gpl-nt MySQL Enterprise Server - Pro Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> select * from world.city where countrycode='usa' limit 3;
+------+-------------+-------------+------------+------------+
| ID   | Name        | CountryCode | District   | Population |
+------+-------------+-------------+------------+------------+
| 3793 | New York    | USA         | New York   |    8008278 |
| 3794 | Los Angeles | USA         | California |    3694820 |
| 3795 | Chicago     | USA         | Illinois   |    2896016 |
+------+-------------+-------------+------------+------------+
3 rows in set (0.15 sec)

mysql> exit
Bye

C:\Users\Chris>

And here is the full script, trace.lua:

function connect_server()
	print("/* Entering function connect_server() */")
	print("   When the proxy accepts a connection from a MySQL client, the")
	print("   connect_server() function is called.  There are no arguments")
	print("   to the function, but you can use and if necessary manipulate")
	print("   the information in the proxy.connection table, which is unique")
	print("   to each client session.\n")
	print("   INTERNAL CONSTANTS:\n")
	print("   //Proxy Return State Constants:")
	print("   proxy.PROXY_SEND_QUERY                       = "
				.. proxy.PROXY_SEND_QUERY)
	print("   proxy.PROXY_SEND_RESULT                      = "
				.. proxy.PROXY_SEND_RESULT)
	print("   proxy.PROXY_IGNORE_RESULT                    = "
				.. proxy.PROXY_IGNORE_RESULT .. "\n")
	print("   //Packet State Constants:")
	print("   proxy.MYSQLD_PACKET_OK                       = "
				.. proxy.MYSQLD_PACKET_OK)
	print("   proxy.MYSQLD_PACKET_ERR                      = "
				.. proxy.MYSQLD_PACKET_ERR)
	print("   proxy.MYSQLD_PACKET_RAW                      = "
				.. proxy.MYSQLD_PACKET_RAW .. "\n")
	print("   //Backend State/Type Constants:")
	print("   proxy.BACKEND_STATE_UNKNOWN                  = "
				.. proxy.BACKEND_STATE_UNKNOWN)
	print("   proxy.BACKEND_STATE_UP                       = "
				.. proxy.BACKEND_STATE_UP)
	print("   proxy.BACKEND_STATE_DOWN                     = "
				.. proxy.BACKEND_STATE_DOWN)
	print("   proxy.BACKEND_TYPE_UNKNOWN                   = "
				.. proxy.BACKEND_TYPE_UNKNOWN)
	print("   proxy.BACKEND_TYPE_RW                        = "
				.. proxy.BACKEND_TYPE_RW)
	print("   proxy.BACKEND_TYPE_RO                        = "
				.. proxy.BACKEND_TYPE_RO .. "\n")
	print("   //Server Command Constants:")
	print("   proxy.COM_SLEEP                              = "
				.. proxy.COM_SLEEP)
	print("   proxy.COM_QUIT                               = "
				.. proxy.COM_QUIT)
	print("   proxy.COM_INIT_DB                            = "
				.. proxy.COM_INIT_DB)
	print("   proxy.COM_QUERY                              = "
				.. proxy.COM_QUERY)
	print("   proxy.COM_FIELD_LIST                         = "
				.. proxy.COM_FIELD_LIST)
	print("   proxy.COM_CREATE_DB                          = "
				.. proxy.COM_CREATE_DB)
	print("   proxy.COM_DROP_DB                            = "
				.. proxy.COM_DROP_DB)
	print("   proxy.COM_REFRESH                            = "
				.. proxy.COM_REFRESH)
	print("   proxy.COM_SHUTDOWN                           = "
				.. proxy.COM_SHUTDOWN)
	print("   proxy.COM_STATISTICS                         = "
				.. proxy.COM_STATISTICS)
	print("   proxy.COM_PROCESS_INFO                       = "
				.. proxy.COM_PROCESS_INFO)
	print("   proxy.COM_CONNECT                            = "
				.. proxy.COM_CONNECT)
	print("   proxy.COM_PROCESS_KILL                       = "
				.. proxy.COM_PROCESS_KILL)
	print("   proxy.COM_DEBUG                              = "
				.. proxy.COM_DEBUG)
	print("   proxy.COM_PING                               = "
				.. proxy.COM_PING)
	print("   proxy.COM_TIME                               = "
				.. proxy.COM_TIME)
	print("   proxy.COM_DELAYED_INSERT                     = "
				.. proxy.COM_DELAYED_INSERT)
	print("   proxy.COM_CHANGE_USER                        = "
				.. proxy.COM_CHANGE_USER)
	print("   proxy.COM_BINLOG_DUMP                        = "
				.. proxy.COM_BINLOG_DUMP)
	print("   proxy.COM_TABLE_DUMP                         = "
				.. proxy.COM_TABLE_DUMP)
	print("   proxy.COM_CONNECT_OUT                        = "
				.. proxy.COM_CONNECT_OUT)
	print("   proxy.COM_REGISTER_SLAVE                     = "
				.. proxy.COM_REGISTER_SLAVE)
	print("   proxy.COM_STMT_PREPARE                       = "
				.. proxy.COM_STMT_PREPARE)
	print("   proxy.COM_STMT_EXECUTE                       = "
				.. proxy.COM_STMT_EXECUTE)
	print("   proxy.COM_STMT_SEND_LONG_DATA                = "
				.. proxy.COM_STMT_SEND_LONG_DATA)
	print("   proxy.COM_STMT_CLOSE                         = "
				.. proxy.COM_STMT_CLOSE)
	print("   proxy.COM_STMT_RESET                         = "
				.. proxy.COM_STMT_RESET)
	print("   proxy.COM_SET_OPTION                         = "
				.. proxy.COM_SET_OPTION)
	print("   proxy.COM_STMT_FETCH                         = "
				.. proxy.COM_STMT_FETCH)
	print("   proxy.COM_DAEMON                             = "
				.. proxy.COM_DAEMON .. "\n")
	print("   //MySQL Type Constants:")
	print("   proxy.MYSQL_TYPE_DECIMAL                     = "
				.. proxy.MYSQL_TYPE_DECIMAL)
	print("   proxy.MYSQL_TYPE_NEWDECIMAL                  = "
				.. proxy.MYSQL_TYPE_NEWDECIMAL)
	print("   proxy.MYSQL_TYPE_TINY                        = "
				.. proxy.MYSQL_TYPE_TINY)
	print("   proxy.MYSQL_TYPE_SHORT                       = "
				.. proxy.MYSQL_TYPE_SHORT)
	print("   proxy.MYSQL_TYPE_LONG                        = "
				.. proxy.MYSQL_TYPE_LONG)
	print("   proxy.MYSQL_TYPE_FLOAT                       = "
				.. proxy.MYSQL_TYPE_FLOAT)
	print("   proxy.MYSQL_TYPE_DOUBLE                      = "
				.. proxy.MYSQL_TYPE_DOUBLE)
	print("   proxy.MYSQL_TYPE_NULL                        = "
				.. proxy.MYSQL_TYPE_NULL)
	print("   proxy.MYSQL_TYPE_TIMESTAMP                   = "
				.. proxy.MYSQL_TYPE_TIMESTAMP)
	print("   proxy.MYSQL_TYPE_LONGLONG                    = "
				.. proxy.MYSQL_TYPE_LONGLONG)
	print("   proxy.MYSQL_TYPE_INT24                       = "
				.. proxy.MYSQL_TYPE_INT24)
	print("   proxy.MYSQL_TYPE_DATE                        = "
				.. proxy.MYSQL_TYPE_DATE)
	print("   proxy.MYSQL_TYPE_TIME                        = "
				.. proxy.MYSQL_TYPE_TIME)
	print("   proxy.MYSQL_TYPE_DATETIME                    = "
				.. proxy.MYSQL_TYPE_DATETIME)
	print("   proxy.MYSQL_TYPE_YEAR                        = "
				.. proxy.MYSQL_TYPE_YEAR)
	print("   proxy.MYSQL_TYPE_NEWDATE                     = "
				.. proxy.MYSQL_TYPE_NEWDATE)
	print("   proxy.MYSQL_TYPE_ENUM                        = "
				.. proxy.MYSQL_TYPE_ENUM)
	print("   proxy.MYSQL_TYPE_SET                         = "
				.. proxy.MYSQL_TYPE_SET)
	print("   proxy.MYSQL_TYPE_TINY_BLOB                   = "
				.. proxy.MYSQL_TYPE_TINY_BLOB)
	print("   proxy.MYSQL_TYPE_MEDIUM_BLOB                 = "
				.. proxy.MYSQL_TYPE_MEDIUM_BLOB)
	print("   proxy.MYSQL_TYPE_LONG_BLOB                   = "
				.. proxy.MYSQL_TYPE_LONG_BLOB)
	print("   proxy.MYSQL_TYPE_BLOB                        = "
				.. proxy.MYSQL_TYPE_BLOB)
	print("   proxy.MYSQL_TYPE_VAR_STRING                  = "
				.. proxy.MYSQL_TYPE_VAR_STRING)
	print("   proxy.MYSQL_TYPE_STRING                      = "
				.. proxy.MYSQL_TYPE_STRING)
	print("   proxy.MYSQL_TYPE_TINY                        = "
				.. proxy.MYSQL_TYPE_TINY)
	print("   proxy.MYSQL_TYPE_ENUM                        = "
				.. proxy.MYSQL_TYPE_ENUM)
	print("   proxy.MYSQL_TYPE_GEOMETRY                    = "
				.. proxy.MYSQL_TYPE_GEOMETRY)
	print("   proxy.MYSQL_TYPE_BIT                         = "
				.. proxy.MYSQL_TYPE_BIT .. "\n")
end

function read_handshake()
	print("/* Entering function read_handshake() */")
	print("   Handshake information is sent by the server to the client")
	print("   after the initial connection (through connect_server()) has")
	print("   been made.  read_handshake() doesn't receive a parameter")
	print("   anymore. Instead all the data is available in the connection")
	print("   tables.\n")
end

function read_auth()
	print("/* Entering function read_auth() */")
	print("   The read_auth() function is triggered when an authentication")
	print("   handshake is initiated by the client.  read_auth() doesn't")
	print("   receive a parameter anymore. Instead all the data is")
	print("   available in the connection tables.\n")
end

function read_auth_result()
	print("/* Entering function read_auth_result() */")
	print("   The return packet from the server during authentication is")
	print("   captured by read_auth_result().\n")
end

function read_query( packet )
	print("/* Entering function read_query( packet ) */")
	o = ""
	for k, v in pairs(proxy.global) do
		o = o .. (("[%s] %s (type=%s)\n"):format(k, tostring(v), type(v)))
	end
	print("| o = " .. o)
	if string.byte(packet) == proxy.COM_QUERY then
		proxy.queries:append(1, packet, {resultset_is_needed = true} )
        print("| Query               = "
			.. string.sub(packet, 2))
		print("| Time Stamp          = "
			.. os.date('%Y-%m-%d %H:%M:%S'))
		print("| Proxy Version       = "
			.. string.format("%05x", proxy.PROXY_VERSION))
		print("| Lua Version         = "
			.. _VERSION)
		return proxy.PROXY_SEND_QUERY
	end
end

function read_query_result( inj )
	print("\n/* Entering function read_query_result( inj ) */")
	local res         = assert(inj.resultset)
	local raw_len     = assert(res.raw):len()
	local packet      = assert(inj.query)
	local flags       = res.flags
	local backend_ndx = proxy.connection.backend_ndx
	print("| os.date                                      = "
		.. os.date('%Y-%m-%d %H:%M:%S'))
	print("| inj.query                                    = "
		.. inj.query)
	print("| proxy.connection.server.scramble_buffer      = "
		.. string.format("%q",proxy.connection.server.scramble_buffer))
	print("| proxy.connection.server.mysqld_version       = "
		.. proxy.connection.server.mysqld_version)
	print("| proxy.connection.server.thread_id            = "
		.. proxy.connection.server.thread_id)
	print("| proxy.connection.client.default_db           = "
		.. proxy.connection.client.default_db)
	print("| proxy.connection.client.username             = "
		.. proxy.connection.client.username)
	print("| proxy.connection.client.scrambled_password   = "
		.. string.format("%q", proxy.connection.client.scrambled_password))
	print("| proxy.connection.client.dst.name             = "
		.. proxy.connection.client.dst.name)
	print("| proxy.connection.client.dst.address          = "
		.. proxy.connection.client.dst.address)
	print("| proxy.connection.client.dst.port             = "
		.. proxy.connection.client.dst.port)
	print("| proxy.connection.server.dst.name             = "
		.. proxy.connection.server.dst.name)
	print("| proxy.connection.server.dst.address          = "
		.. proxy.connection.server.dst.address)
	print("| proxy.connection.server.dst.port             = "
		.. proxy.connection.server.dst.port)
	print("| proxy.connection.client.src.name             = "
		.. proxy.connection.client.src.name)
	print("| proxy.connection.client.src.address          = "
		.. proxy.connection.client.src.address)
	print("| proxy.connection.client.src.port             = "
		.. proxy.connection.client.src.port)
	print("| proxy.connection.server.src.name             = "
		.. proxy.connection.server.src.name)
	print("| proxy.connection.server.src.address          = "
		.. proxy.connection.server.src.address)
	print("| proxy.connection.server.src.port             = "
		.. proxy.connection.server.src.port)
	print("| inj.query-time                               = "
		.. (inj.query_time / 1000) .. "ms")
	print("| inj.response-time                            = "
		.. (inj.response_time / 1000) .. "ms")
	print("| proxy.connection.backend_ndx                 = "
		.. proxy.connection.backend_ndx)
	print("| #proxy.global.backends                       = "
		.. #proxy.global.backends)
	print("| proxy.global.backends[ndx].dst.name          = "
		.. proxy.global.backends[backend_ndx].dst.name)
	print("| proxy.global.backends[ndx].dst.address       = "
		.. proxy.global.backends[backend_ndx].dst.address)
	print("| proxy.global.backends[ndx].dst.port          = "
		.. proxy.global.backends[backend_ndx].dst.port)
	print("| proxy.global.backends[ndx].connected_clients = "
		.. proxy.global.backends[backend_ndx].connected_clients)
	print("| proxy.global.backends[ndx].state             = "
		.. proxy.global.backends[backend_ndx].state)
	print("| proxy.global.backends[ndx].type              = "
		.. proxy.global.backends[backend_ndx].type)
	print("| proxy.global.backends[ndx].pool.max_idle_connections = "
		.. proxy.global.backends[backend_ndx].pool.max_idle_connections)
	print("| proxy.global.backends[ndx].pool.min_idle_connections = "
		.. proxy.global.backends[backend_ndx].pool.min_idle_connections)
	print("| proxy.global.backends[ndx].pool.users[1]     = "
		.. proxy.global.backends[backend_ndx].pool.users[1].cur_idle_connections)
	print("| result.len                                   = "
		.. raw_len)
	print("| result.flags.in_trans                        = "
		.. tostring(res.flags.in_trans))
	print("| result.flags.auto_commit                     = "
		.. tostring(res.flags.auto_commit))
	print("| result.flags.no_good_index_used              = "
		.. tostring(res.flags.no_good_index_used))
	print("| result.flags.no_index_used                   = "
		.. tostring(res.flags.no_index_used))
	print("| result.flags.cursor_exists                   = "
		.. tostring(res.flags.cursor_exists))
	print("| result.flags.last_row_sent                   = "
		.. tostring(res.flags.last_row_sent))
	print("| result.flags.db_dropped                      = "
		.. tostring(res.flags.db_dropped))
	print("| result.flags.no_backslash_escapes            = "
		.. tostring(res.flags.no_backslash_escapes))
	print("| result.flags.metadata_changed                = "
		.. tostring(res.flags.metadata_changed))
	print("| result.warning_count                         = "
		.. res.warning_count)
	print("| result.query_status                          = "
		.. res.query_status)
	if res.affected_rows then
		print("| result.affected_rows                         = "
			.. res.affected_rows)
		print("| result.insert_id                             = "
			.. res.insert_id)
	end
	if res.query_status == proxy.MYSQLD_PACKET_ERR then
		print("| result.err.code                              = "
			.. res.raw:byte(2) + (res.raw:byte(3) * 256))
		print("| result.err.sql_state                         = "
			.. string.format("%q", res.raw:sub(5, 9)))
		print("| result.err.msg                               = "
			.. string.format("%q", res.raw:sub(10)))
	end
	if res.query_status == proxy.MYSQLD_PACKET_OK then
		print("| result.fields[1].type                        = "
			.. res.fields[1].type)
		print("| result.fields[1].name                        = "
			.. res.fields[1].name)
		local row_count = 0
		for row in inj.resultset.rows do
			for i,v in ipairs(row) do print(i,v) end
			row_count = row_count + 1
		end
		print("| row_count                                    = "
			.. row_count)
	end
	print("\n")
end

function disconnect_client()
	print("/* Entering function disconnect_client() */")
	if proxy.connection.server.thread_id then
		print("Client " .. proxy.connection.server.thread_id
			.. " has disconnected.")
	end
end

I hope this helps, and happy proxy tracing. ;)

Tags: , , , , , , , , , , , , ,

2 Responses to “Proxy Trace Revisited with MySQL Proxy 0.8.2”

  1. vestiyuga says:

    Interesting article. Very informative and precise.

  2. MarkusQ says:

    Thank you! You saved me some time on a day when I really needed it!


Period Panties by Period Panteez Menstrual Underwear Menstruation PMS Panty