--- a/sql/log.cc 2014-12-09 16:11:39.000000000 -0700 +++ b/sql/log.cc 2014-12-09 16:09:09.000000000 -0700 @@ -4916,6 +4916,8 @@ int THD::binlog_setup_trx_data() { + char* tmpdir_to_use; + DBUG_ENTER("THD::binlog_setup_trx_data"); binlog_cache_mngr *cache_mngr= (binlog_cache_mngr*) thd_get_ha_data(this, binlog_hton); @@ -4924,10 +4926,18 @@ DBUG_RETURN(0); // Already set up cache_mngr= (binlog_cache_mngr*) my_malloc(sizeof(binlog_cache_mngr), MYF(MY_ZEROFILL)); + if (!opt_mysql_binlog_tmpdir) + { + tmpdir_to_use= mysql_tmpdir; + } + else + { + tmpdir_to_use= opt_mysql_binlog_tmpdir; + } if (!cache_mngr || - open_cached_file(&cache_mngr->stmt_cache.cache_log, mysql_tmpdir, + open_cached_file(&cache_mngr->stmt_cache.cache_log, tmpdir_to_use, LOG_PREFIX, binlog_stmt_cache_size, MYF(MY_WME)) || - open_cached_file(&cache_mngr->trx_cache.cache_log, mysql_tmpdir, + open_cached_file(&cache_mngr->trx_cache.cache_log, tmpdir_to_use, LOG_PREFIX, binlog_cache_size, MYF(MY_WME))) { my_free(cache_mngr); diff -ruN a/sql/mysqld.cc b/sql/mysqld.cc --- a/sql/mysqld.cc 2014-12-08 16:01:37.000000000 -0700 +++ b/sql/mysqld.cc 2014-12-09 16:09:09.000000000 -0700 @@ -602,7 +602,7 @@ char *mysql_data_home= const_cast("."); const char *mysql_real_data_home_ptr= mysql_real_data_home; char server_version[SERVER_VERSION_LENGTH]; -char *mysqld_unix_port, *opt_mysql_tmpdir; +char *mysqld_unix_port, *opt_mysql_tmpdir, *opt_mysql_binlog_tmpdir; ulong thread_handling; /** name of reference on left expression in rewritten IN subquery */ diff -ruN a/sql/mysqld.h b/sql/mysqld.h --- a/sql/mysqld.h 2014-12-08 16:01:37.000000000 -0700 +++ b/sql/mysqld.h 2014-12-09 16:09:09.000000000 -0700 @@ -212,6 +212,7 @@ extern int cachedev_fd; extern time_t server_start_time, flush_status_time; extern char *opt_mysql_tmpdir, mysql_charsets_dir[]; +extern char *opt_mysql_binlog_tmpdir; extern int mysql_unpacked_real_data_home_len; extern MYSQL_PLUGIN_IMPORT MY_TMPDIR mysql_tmpdir_list; extern const char *first_keyword, *delayed_user, *binary_keyword; diff -ruN a/sql/sys_vars.cc b/sql/sys_vars.cc --- a/sql/sys_vars.cc 2014-12-09 16:11:39.000000000 -0700 +++ b/sql/sys_vars.cc 2014-12-09 16:09:10.000000000 -0700 @@ -1927,6 +1927,11 @@ READ_ONLY GLOBAL_VAR(opt_mysql_tmpdir), CMD_LINE(REQUIRED_ARG, 't'), IN_FS_CHARSET, DEFAULT(0)); +static Sys_var_charptr Sys_binlog_tmpdir( + "binlog_tmpdir", "Path for binlog temporary files.", + READ_ONLY GLOBAL_VAR(opt_mysql_binlog_tmpdir), CMD_LINE(REQUIRED_ARG, 't'), + IN_FS_CHARSET, DEFAULT(0)); + static bool fix_trans_mem_root(sys_var *self, THD *thd, enum_var_type type) { if (type != OPT_GLOBAL)