diff --git a/mysql-test/r/ndb_partition_range.result b/mysql-test/r/ndb_partition_range.result
index 5297e2a733ddb8526f020fc3619e433c561ac5b7..cb79f04873ec13f61d973c8005607d3c0b8c94d0 100644
--- a/mysql-test/r/ndb_partition_range.result
+++ b/mysql-test/r/ndb_partition_range.result
@@ -246,17 +246,17 @@ PARTITION BY RANGE(f1)
 PARTITION part2 VALUES LESS THAN (1000));
 INSERT INTO t1 VALUES(1, '---1---');
 INSERT INTO t1 VALUES(2, '---2---');
-select * from t1;
+select * from t1 order by f1;
 f1	f2
 1	---1---
 2	---2---
 UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2;
-select * from t1;
+select * from t1 order by f1;
 f1	f2
 1	---1---
 6	---2---
 UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1;
-select * from t1;
+select * from t1 order by f1;
 f1	f2
 5	---1---
 6	---2---
diff --git a/mysql-test/t/ndb_partition_range.test b/mysql-test/t/ndb_partition_range.test
index e64dc80886ac11b9e18be346aa46199d9f21560a..981467d40550d50e1c197260577758a89c37a169 100644
--- a/mysql-test/t/ndb_partition_range.test
+++ b/mysql-test/t/ndb_partition_range.test
@@ -252,9 +252,9 @@ PARTITION BY RANGE(f1)
 PARTITION part2 VALUES LESS THAN (1000));
 INSERT INTO t1 VALUES(1, '---1---');
 INSERT INTO t1 VALUES(2, '---2---');
-select * from t1;
+select * from t1 order by f1;
 UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 2;
-select * from t1;
+select * from t1 order by f1;
 UPDATE t1 SET f1 = f1 + 4 WHERE f1 = 1;
-select * from t1;
+select * from t1 order by f1;
 drop table t1;
diff --git a/sql/ha_ndbcluster.cc b/sql/ha_ndbcluster.cc
index ae907077ab1960ac2cb7e6a40e264d3fe12dc3da..ff8a1221052514e7bd5a5652887eca3bcb2fbe53 100644
--- a/sql/ha_ndbcluster.cc
+++ b/sql/ha_ndbcluster.cc
@@ -4728,13 +4728,14 @@ int ha_ndbcluster::final_drop_index(TABLE *table_arg)
 int ha_ndbcluster::rename_table(const char *from, const char *to)
 {
   NDBDICT *dict;
+  char old_dbname[FN_HEADLEN];
   char new_tabname[FN_HEADLEN];
   const NDBTAB *orig_tab;
   int result;
 
   DBUG_ENTER("ha_ndbcluster::rename_table");
   DBUG_PRINT("info", ("Renaming %s to %s", from, to));
-  set_dbname(from);
+  set_dbname(from, old_dbname);
   set_tabname(from);
   set_tabname(to, new_tabname);
 
@@ -4742,6 +4743,7 @@ int ha_ndbcluster::rename_table(const char *from, const char *to)
     DBUG_RETURN(my_errno= HA_ERR_NO_CONNECTION);
 
   Ndb *ndb= get_ndb();
+  ndb->setDatabaseName(old_dbname);
   dict= ndb->getDictionary();
   if (!(orig_tab= dict->getTable(m_tabname)))
     ERR_RETURN(dict->getNdbError());
@@ -4833,7 +4835,8 @@ int ha_ndbcluster::rename_table(const char *from, const char *to)
                                current_thd->query, current_thd->query_length,
                                m_dbname, new_tabname,
                                0, 0,
-                               SOT_RENAME_TABLE);
+                               SOT_RENAME_TABLE,
+                               old_dbname, m_tabname);
   }
   if (share)
     free_share(&share);
diff --git a/sql/ha_ndbcluster_binlog.cc b/sql/ha_ndbcluster_binlog.cc
index b756e1e3fe8db89f9ae1c8aeccf8578321e58128..f88c118b46e080155f6148f5ac651ed228bcc010 100644
--- a/sql/ha_ndbcluster_binlog.cc
+++ b/sql/ha_ndbcluster_binlog.cc
@@ -885,7 +885,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
                              const char *db, const char *table_name,
                              uint32 ndb_table_id,
                              uint32 ndb_table_version,
-                             enum SCHEMA_OP_TYPE type)
+                             enum SCHEMA_OP_TYPE type,
+                             const char *old_db, const char *old_table_name)
 {
   DBUG_ENTER("ndbcluster_log_schema_op");
   Thd_ndb *thd_ndb= get_thd_ndb(thd);
@@ -919,10 +920,19 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
     query= tmp_buf2;
     query_length= (uint) (strxmov(tmp_buf2, "drop table `",
                                   table_name, "`", NullS) - tmp_buf2);
-    // fall through
-  case SOT_CREATE_TABLE:
-    // fall through
+    if (!share)
+      get_a_share= 1;
+    break;
   case SOT_RENAME_TABLE:
+    /* redo the rename table query as is may contain several tables */
+    query= tmp_buf2;
+    query_length= (uint) (strxmov(tmp_buf2, "rename table `",
+                                  old_db, ".", old_table_name, "` to `",
+                                  db, ".", table_name, "`", NullS) - tmp_buf2);
+    if (!share)
+      get_a_share= 1;
+    break;
+  case SOT_CREATE_TABLE:
     // fall through
   case SOT_ALTER_TABLE:
     if (!share)
@@ -983,8 +993,8 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
   }
 
   Ndb *ndb= thd_ndb->ndb;
-  char old_db[FN_REFLEN];
-  strcpy(old_db, ndb->getDatabaseName());
+  char save_db[FN_REFLEN];
+  strcpy(save_db, ndb->getDatabaseName());
 
   char tmp_buf[SCHEMA_QUERY_SIZE];
   NDBDICT *dict= ndb->getDictionary();
@@ -1091,7 +1101,7 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
           
   if (trans)
     ndb->closeTransaction(trans);
-  ndb->setDatabaseName(old_db);
+  ndb->setDatabaseName(save_db);
 
   /*
     Wait for other mysqld's to acknowledge the table operation
@@ -1169,8 +1179,8 @@ ndbcluster_update_slock(THD *thd,
   const NdbError *ndb_error= 0;
   uint32 node_id= g_ndb_cluster_connection->node_id();
   Ndb *ndb= check_ndb_in_thd(thd);
-  char old_db[128];
-  strcpy(old_db, ndb->getDatabaseName());
+  char save_db[FN_HEADLEN];
+  strcpy(save_db, ndb->getDatabaseName());
 
   char tmp_buf[SCHEMA_QUERY_SIZE];
   NDBDICT *dict= ndb->getDictionary();
@@ -1292,7 +1302,7 @@ ndbcluster_update_slock(THD *thd,
                         db, table_name);
   if (trans)
     ndb->closeTransaction(trans);
-  ndb->setDatabaseName(old_db);
+  ndb->setDatabaseName(save_db);
   DBUG_RETURN(0);
 }
 
diff --git a/sql/ha_ndbcluster_binlog.h b/sql/ha_ndbcluster_binlog.h
index d9c8812b3b60bda0ebe3690fde643db436de08f3..91ef53edd6b30146b4ffd567d2c439d09d6a1170 100644
--- a/sql/ha_ndbcluster_binlog.h
+++ b/sql/ha_ndbcluster_binlog.h
@@ -95,7 +95,9 @@ int ndbcluster_log_schema_op(THD *thd, NDB_SHARE *share,
                              const char *db, const char *table_name,
                              uint32 ndb_table_id,
                              uint32 ndb_table_version,
-                             enum SCHEMA_OP_TYPE type);
+                             enum SCHEMA_OP_TYPE type,
+                             const char *old_db= 0,
+                             const char *old_table_name= 0);
 int ndbcluster_handle_drop_table(Ndb *ndb, const char *event_name,
                                  NDB_SHARE *share);
 void ndb_rep_event_name(String *event_name,