diff -ru ../mysql-5.1.22-rc-dist/include/mysql_com.h ./include/mysql_com.h --- ../mysql-5.1.22-rc-dist/include/mysql_com.h 2007-09-24 06:29:33.000000000 -0400 +++ ./include/mysql_com.h 2007-12-27 13:09:11.000000000 -0500 @@ -115,6 +115,8 @@ #define REFRESH_MASTER 128 /* Remove all bin logs in the index and truncate the index */ +#define REFRESH_CONNECTION 256 /* restore session to default */ + /* The following can't be set with mysql_refresh() */ #define REFRESH_READ_LOCK 16384 /* Lock tables for read */ #define REFRESH_FAST 32768 /* Intern flag */ diff -ru ../mysql-5.1.22-rc-dist/sql/sql_parse.cc ./sql/sql_parse.cc --- ../mysql-5.1.22-rc-dist/sql/sql_parse.cc 2007-09-24 06:30:14.000000000 -0400 +++ ./sql/sql_parse.cc 2007-12-27 13:12:04.000000000 -0500 @@ -6396,6 +6396,14 @@ result=close_cached_tables(thd,(options & REFRESH_FAST) ? 0 : 1, tables); my_dbopt_cleanup(); } + if (options && REFRESH_CONNECTION) + { + if (reset_connection(thd)) + { + result=1; + thd->fatal_error(); + } + } if (options & REFRESH_HOSTS) hostname_cache_refresh(); if (thd && (options & REFRESH_STATUS)) diff -ru ../mysql-5.1.22-rc-dist/sql/sql_repl.cc ./sql/sql_repl.cc --- ../mysql-5.1.22-rc-dist/sql/sql_repl.cc 2007-09-24 06:29:58.000000000 -0400 +++ ./sql/sql_repl.cc 2007-12-27 13:14:57.000000000 -0500 @@ -1019,6 +1019,36 @@ } /* + Reset a connection - destroys all temporary tables, + session variables, routine cache, prepared statements + associated with a connection (thd). + + SYNOPSIS + reset_connection() + thd Thread handler + + RETURN + 0 ok + 1 error + +*/ + +int reset_connection (THD *thd) +{ + + status_var_increment(thd->status_var.com_other); + + thd->change_user(); + thd->clear_error(); // if errors from rollback + + /* Clear variables that are allocated */ + thd->user_connect= 0; + + return 0; + +} + +/* Kill all Binlog_dump threads which previously talked to the same slave ("same" means with the same server id). Indeed, if the slave stops, if the diff -ru ../mysql-5.1.22-rc-dist/sql/sql_repl.h ./sql/sql_repl.h --- ../mysql-5.1.22-rc-dist/sql/sql_repl.h 2007-09-24 06:30:24.000000000 -0400 +++ ./sql/sql_repl.h 2007-12-27 13:13:23.000000000 -0500 @@ -50,6 +50,7 @@ const char* log_file_name2, ulonglong log_pos2); int reset_slave(THD *thd, MASTER_INFO* mi); int reset_master(THD* thd); +int reset_connection(THD *thd); bool purge_master_logs(THD* thd, const char* to_log); bool purge_master_logs_before_date(THD* thd, time_t purge_time); bool log_in_use(const char* log_name);