diff --git a/strings/ctype-bin.c b/strings/ctype-bin.c
index c11be2e5926..8e9d11ab146 100644
--- a/strings/ctype-bin.c
+++ b/strings/ctype-bin.c
@@ -23,6 +23,18 @@
 #include "strings_def.h"
 #include <m_ctype.h>
 
+static inline int
+my_strnncoll_4byte_as_uint32(const uchar *s, const uchar *t)
+{
+  u_int32_t si= __bswap_32(((u_int32_t*) s)[0]);
+  u_int32_t ti= __bswap_32(((u_int32_t*) t)[0]);
+  if (si < ti)
+    return -1;
+  if (si > ti)
+    return 1;
+  return 0;
+}
+
 const char charset_name_binary[]= "binary";
 
 static const uchar ctype_bin[]=
@@ -84,7 +96,11 @@ static int my_strnncoll_binary(CHARSET_INFO * cs __attribute__((unused)),
                                my_bool t_is_prefix)
 {
   size_t len=MY_MIN(slen,tlen);
-  int cmp= memcmp(s,t,len);
+  int cmp;
+  if (len==4)
+    cmp= my_strnncoll_4byte_as_uint32(s, t);
+  else
+    cmp= memcmp(s,t,len);
   return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
 }
 
@@ -133,7 +149,11 @@ static int my_strnncoll_8bit_bin(CHARSET_INFO * cs __attribute__((unused)),
                                  my_bool t_is_prefix)
 {
   size_t len=MY_MIN(slen,tlen);
-  int cmp= memcmp(s,t,len);
+  int cmp;
+  if (len==4)
+    cmp= my_strnncoll_4byte_as_uint32(s, t);
+  else
+    cmp= memcmp(s,t,len);
   return cmp ? cmp : (int)((t_is_prefix ? len : slen) - tlen);
 }
 
@@ -189,7 +209,13 @@ static int my_strnncollsp_8bit_bin(CHARSET_INFO * cs __attribute__((unused)),
   size_t length;
 
   end= a + (length= MY_MIN(a_length, b_length));
-  while (a < end)
+  if (length == 4)
+  {
+    int cmp= my_strnncoll_4byte_as_uint32(a, b);
+    if (cmp)
+      return cmp;
+  }
+  else while (a < end)
   {
     if (*a++ != *b++)
       return ((int) a[-1] - (int) b[-1]);
