Created
February 6, 2020 13:04
-
-
Save insom/ddb245dfa9d971ccf33bee504ffb7e52 to your computer and use it in GitHub Desktop.
MySQL Session Tracking for ALL_GTIDS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdio> | |
#include <mysql.h> | |
void retrieve_session_track_data(MYSQL *m) { | |
const char *data; | |
size_t length; | |
for(int type=0; type <= 255; type++) { | |
if (mysql_session_track_get_first(m, (enum enum_session_state_type) type, &data, &length) == 0) { | |
do { | |
printf("Got session track data: type=%d, length=%d, data=%*s\n", | |
type, (int) length, (int) length, data); | |
} while(mysql_session_track_get_next(m, (enum enum_session_state_type) type, &data, &length) == 0); | |
} | |
} | |
} | |
int main() { | |
MYSQL mysql; | |
MYSQL_RES *res; | |
MYSQL_ROW row; | |
mysql_init(&mysql); | |
if (!mysql_real_connect(&mysql, | |
"127.0.0.1", | |
"root", | |
"boop", | |
"test", | |
3309, | |
NULL, | |
CLIENT_BASIC_FLAGS | CLIENT_SESSION_TRACK)) { | |
printf("Error in mysql_real_connect: %d: %s\n", mysql_errno(&mysql), mysql_error(&mysql)); | |
goto exit_0; | |
} | |
printf("running 'SET SESSION session_track_gtids=ALL_GTIDS'\n"); | |
if (mysql_query(&mysql, "SET SESSION session_track_gtids=ALL_GTIDS") != 0) { | |
printf("Error enabling session_track_gtids: %d: %s\n", mysql_errno(&mysql), mysql_error(&mysql)); | |
goto exit_1; | |
} | |
/* | |
if (mysql_query(&mysql, "insert into test.test values (1)")) { | |
printf("Error in mysql_query: %d: %s\n", mysql_errno(&mysql), mysql_error(&mysql)); | |
goto exit_1; | |
} | |
*/ | |
printf("running 'select 1'\n"); | |
if (mysql_query(&mysql, "select 1") != 0) { | |
printf("Error in mysql_query: %d: %s\n", mysql_errno(&mysql), mysql_error(&mysql)); | |
goto exit_1; | |
} | |
res = mysql_store_result(&mysql); | |
if (!res) { | |
printf("Error in mysql_store_result: %d: %s\n", mysql_errno(&mysql), mysql_error(&mysql)); | |
goto exit_2; | |
} | |
row = mysql_fetch_row(res); | |
printf("Got a result: %s\n", row[0]); | |
printf("checking OK packet\n"); | |
retrieve_session_track_data(&mysql); | |
exit_2: | |
mysql_free_result(res); | |
exit_1: | |
mysql_close(&mysql); | |
exit_0: | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment