diff --git a/include/mysql_com.h b/include/mysql_com.h
index 2cdda8457ea3f3de76bcf4d899c376dde4bf7d70..d591a02323601e11c6c45e73cbc1749beca23710 100644
--- a/include/mysql_com.h
+++ b/include/mysql_com.h
@@ -478,6 +478,7 @@ typedef struct st_net {
   my_bool thread_specific_malloc;
   unsigned char compress;
   my_bool pkt_nr_can_be_reset;
+  my_bool using_proxy_protocol;
   /*
     Pointer to query object in query cache, do not equal NULL (0) for
     queries in cache that have not stored its results yet
diff --git a/mysql-test/main/mysql_client_test.result b/mysql-test/main/mysql_client_test.result
index dbc1feaa23ba2ec8f1caeb5c01b2124b9015790b..dbd5aaeaae5725b4b0bb087cfe46f9773a78431d 100644
--- a/mysql-test/main/mysql_client_test.result
+++ b/mysql-test/main/mysql_client_test.result
@@ -261,3 +261,4 @@ SET @@global.character_set_server= @save_character_set_server;
 SET @@global.collation_server= @save_collation_server;
 SET @@global.character_set_client= @save_character_set_client;
 SET @@global.collation_connection= @save_collation_connection;
+FOUND 1 /Aborted connection.*'u' host: '192.0.2.1' real ip: '(localhost|::1)'/ in mysqld.1.err
diff --git a/mysql-test/main/mysql_client_test.test b/mysql-test/main/mysql_client_test.test
index bcb246a8a06d810ba11d0ee6c27f00124c5f3d5a..0de459bd316dacdc1865d94701012e052b2dbc4a 100644
--- a/mysql-test/main/mysql_client_test.test
+++ b/mysql-test/main/mysql_client_test.test
@@ -57,3 +57,9 @@ SET @@global.character_set_server= @save_character_set_server;
 SET @@global.collation_server= @save_collation_server;
 SET @@global.character_set_client= @save_character_set_client;
 SET @@global.collation_connection= @save_collation_connection;
+
+# Search for "real ip" in Aborted message
+# This is indicator for abort of the proxied connections.
+let SEARCH_FILE=$MYSQLTEST_VARDIR/log/mysqld.1.err;
+let SEARCH_PATTERN= Aborted connection.*'u' host: '192.0.2.1' real ip: '(localhost|::1)';
+source include/search_pattern_in_file.inc;
diff --git a/sql/net_serv.cc b/sql/net_serv.cc
index b1009b6552b4b4414985bb973f720dd8eeeb4b1e..af65d92c2b9a917fdc1437d553d0989565580398 100644
--- a/sql/net_serv.cc
+++ b/sql/net_serv.cc
@@ -163,6 +163,7 @@ my_bool my_net_init(NET *net, Vio *vio, void *thd, uint my_flags)
   net->net_skip_rest_factor= 0;
   net->last_errno=0;
   net->pkt_nr_can_be_reset= 0;
+  net->using_proxy_protocol= 0;
   net->thread_specific_malloc= MY_TEST(my_flags & MY_THREAD_SPECIFIC);
   net->thd= 0;
 #ifdef MYSQL_SERVER
@@ -217,6 +218,7 @@ void net_end(NET *net)
   DBUG_ENTER("net_end");
   my_free(net->buff);
   net->buff=0;
+  net->using_proxy_protocol= 0;
   DBUG_VOID_RETURN;
 }
 
@@ -955,6 +957,7 @@ static handle_proxy_header_result handle_proxy_header(NET *net)
     return RETRY;
   /* Change peer address in THD and ACL structures.*/
   uint host_errors;
+  net->using_proxy_protocol= 1;
   return (handle_proxy_header_result)thd_set_peer_addr(thd,
                          &(peer_info.peer_addr), NULL, peer_info.port,
                          false, &host_errors);
diff --git a/sql/share/errmsg-utf8.txt b/sql/share/errmsg-utf8.txt
index 890883bcd7b911da49a3d88a07c4122b774afc64..be497b2338c1e11abcb6c1eb901eaf5e7fd8a990 100644
--- a/sql/share/errmsg-utf8.txt
+++ b/sql/share/errmsg-utf8.txt
@@ -4258,22 +4258,22 @@ ER_ERROR_DURING_CHECKPOINT
         swe "Fick fel %M vid CHECKPOINT"
         ukr "袨褌褉懈屑邪薪芯 锌芯屑懈谢泻褍 %M 锌褨写 褔邪褋 CHECKPOINT"
 ER_NEW_ABORTING_CONNECTION 08S01 
-        chi "缁堟鐨勮繛鎺� %lld 鍒版暟鎹簱: '%-.192s' 鐢ㄦ埛: '%-.48s' 涓绘満: '%-.64s' (%-.64s)"
-        cze "Spojen铆 %lld do datab谩ze: '%-.192s' u啪ivatel: '%-.48s' stroj: '%-.64s' (%-.64s) bylo p艡eru拧eno"
-        dan "Afbr酶d forbindelsen %lld til databasen '%-.192s' bruger: '%-.48s' v忙rt: '%-.64s' (%-.64s)"
-        eng "Aborted connection %lld to db: '%-.192s' user: '%-.48s' host: '%-.64s' (%-.64s)"
-        est "脺hendus katkestatud %lld andmebaas: '%-.192s' kasutaja: '%-.48s' masin: '%-.64s' (%-.64s)"
-        fre "Connection %lld avort茅e vers la bd: '%-.192s' utilisateur: '%-.48s' h么te: '%-.64s' (%-.64s)"
-        ger "Abbruch der Verbindung %lld zur Datenbank '%-.192s'. Benutzer: '%-.48s', Host: '%-.64s' (%-.64s)"
-        ita "Interrotta la connessione %lld al db: ''%-.192s' utente: '%-.48s' host: '%-.64s' (%-.64s)"
-        jpn "鎺ョ稓 %lld 銇屼腑鏂仌銈屻伨銇椼仧銆傘儑銉笺偪銉欍兗銈�: '%-.192s' 銉︺兗銈躲兗: '%-.48s' 銉涖偣銉�: '%-.64s' (%-.64s)"
-        nla "Afgebroken verbinding %lld naar db: '%-.192s' gebruiker: '%-.48s' host: '%-.64s' (%-.64s)"
-        por "Conex茫o %lld abortada para banco de dados '%-.192s' - usu谩rio '%-.48s' - 'host' '%-.64s' ('%-.64s')"
-        rus "袩褉械褉胁邪薪芯 褋芯械写懈薪械薪懈械 %lld 泻 斜邪蟹械 写邪薪薪褘褏 '%-.192s' 锌芯谢褜蟹芯胁邪褌械谢褟 '%-.48s' 褋 褏芯褋褌邪 '%-.64s' (%-.64s)"
-        serbian "Prekinuta konekcija broj %lld ka bazi: '%-.192s' korisnik je bio: '%-.48s' a host: '%-.64s' (%-.64s)"
-        spa "Abortada conexi贸n %lld a la base de datos: '%-.192s' usuario: '%-.48s' equipo: '%-.64s' (%-.64s)"
-        swe "Avbr枚t l盲nken f枚r tr氓d %lld till db '%-.192s', anv盲ndare '%-.48s', host '%-.64s' (%-.64s)"
-        ukr "袩械褉械褉胁邪薪芯 蟹'褦写薪邪薪薪褟 %lld 写芯 斜邪蟹懈 写邪薪薪懈褏: '%-.192s' 泻芯褉懈褋褌褍胁邪褔: '%-.48s' 褏芯褋褌: '%-.64s' (%-.64s)"
+        chi "缁堟鐨勮繛鎺� %lld 鍒版暟鎹簱: '%-.192s' 鐢ㄦ埛: '%-.48s' 涓绘満: '%-.64s'%-.64s (%-.64s)"
+        cze "Spojen铆 %lld do datab谩ze: '%-.192s' u啪ivatel: '%-.48s' stroj: '%-.64s'%-.64s (%-.64s) bylo p艡eru拧eno"
+        dan "Afbr酶d forbindelsen %lld til databasen '%-.192s' bruger: '%-.48s' v忙rt: '%-.64s'%-.64s (%-.64s)"
+        eng "Aborted connection %lld to db: '%-.192s' user: '%-.48s' host: '%-.64s'%-.64s (%-.64s)"
+        est "脺hendus katkestatud %lld andmebaas: '%-.192s' kasutaja: '%-.48s' masin: '%-.64s'%-.64s (%-.64s)"
+        fre "Connection %lld avort茅e vers la bd: '%-.192s' utilisateur: '%-.48s' h么te: '%-.64s'%-.64s (%-.64s)"
+        ger "Abbruch der Verbindung %lld zur Datenbank '%-.192s'. Benutzer: '%-.48s', Host: '%-.64s'%-.64s (%-.64s)"
+        ita "Interrotta la connessione %lld al db: ''%-.192s' utente: '%-.48s' host: '%-.64s'%-.64s (%-.64s)"
+        jpn "鎺ョ稓 %lld 銇屼腑鏂仌銈屻伨銇椼仧銆傘儑銉笺偪銉欍兗銈�: '%-.192s' 銉︺兗銈躲兗: '%-.48s' 銉涖偣銉�: '%-.64s'%-.64s (%-.64s)"
+        nla "Afgebroken verbinding %lld naar db: '%-.192s' gebruiker: '%-.48s' host: '%-.64s'%-.64s (%-.64s)"
+        por "Conex茫o %lld abortada para banco de dados '%-.192s' - usu谩rio '%-.48s' - 'host' '%-.64s'%-.64s ('%-.64s')"
+        rus "袩褉械褉胁邪薪芯 褋芯械写懈薪械薪懈械 %lld 泻 斜邪蟹械 写邪薪薪褘褏 '%-.192s' 锌芯谢褜蟹芯胁邪褌械谢褟 '%-.48s' 褋 褏芯褋褌邪 '%-.64s'%-.64s (%-.64s)"
+        serbian "Prekinuta konekcija broj %lld ka bazi: '%-.192s' korisnik je bio: '%-.48s' a host: '%-.64s'%-.64s (%-.64s)"
+        spa "Abortada conexi贸n %lld a la base de datos: '%-.192s' usuario: '%-.48s' equipo: '%-.64s'%-.64s (%-.64s)"
+        swe "Avbr枚t l盲nken f枚r tr氓d %lld till db '%-.192s', anv盲ndare '%-.48s', host '%-.64s'%-.64s (%-.64s)"
+        ukr "袩械褉械褉胁邪薪芯 蟹'褦写薪邪薪薪褟 %lld 写芯 斜邪蟹懈 写邪薪薪懈褏: '%-.192s' 泻芯褉懈褋褌褍胁邪褔: '%-.48s' 褏芯褋褌: '%-.64s'%-.64s (%-.64s)"
 ER_UNUSED_10
         eng "You should never see it"
         spa "Nunca lo deber铆a vd de ver"
diff --git a/sql/sql_class.h b/sql/sql_class.h
index 0aa2aef72c24f7ae1824c999c420477c85390935..29efb45e0974ae83f229467262527fa242e501da 100644
--- a/sql/sql_class.h
+++ b/sql/sql_class.h
@@ -5218,11 +5218,29 @@ class THD: public THD_count, /* this must be first */
   {
     if (global_system_variables.log_warnings > threshold)
     {
+      char real_ip_str[64];
+      real_ip_str[0]= 0;
+
+      /* For proxied connections, add the real IP to the warning message */
+      if (net.using_proxy_protocol && net.vio)
+      {
+        if(net.vio->localhost)
+          snprintf(real_ip_str, sizeof(real_ip_str), " real ip: 'localhost'");
+        else
+        {
+          char buf[INET6_ADDRSTRLEN];
+          if (!vio_getnameinfo((sockaddr *)&(net.vio->remote), buf,
+              sizeof(buf),NULL, 0, NI_NUMERICHOST))
+          {
+            snprintf(real_ip_str, sizeof(real_ip_str), " real ip: '%s'",buf);
+          }
+        }
+      }
       Security_context *sctx= &main_security_ctx;
       sql_print_warning(ER_THD(this, ER_NEW_ABORTING_CONNECTION),
                         thread_id, (db.str ? db.str : "unconnected"),
                         sctx->user ? sctx->user : "unauthenticated",
-                        sctx->host_or_ip, reason);
+                        sctx->host_or_ip, real_ip_str, reason);
     }
   }
 
diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc
index 8878c7225574fe2b62e5a55855742b7d9c5bf0ed..6149cc49ebb34f13d94d826931bd33dfbc520a8e 100644
--- a/sql/sql_connect.cc
+++ b/sql/sql_connect.cc
@@ -1274,7 +1274,7 @@ void prepare_new_connection_state(THD* thd)
                  thd->thread_id,
                  thd->db.str ? thd->db.str : "unconnected",
                  sctx->user ? sctx->user : "unauthenticated",
-                 sctx->host_or_ip, "init_connect command failed");
+                 sctx->host_or_ip, "", "init_connect command failed");
       thd->server_status&= ~SERVER_STATUS_CLEAR_SET;
       thd->protocol->end_statement();
       thd->killed = KILL_CONNECTION;
diff --git a/tests/mysql_client_test.c b/tests/mysql_client_test.c
index 8e2a431078ae11c26c7ab94c5aed5dff88036f32..4443319a3a93129f0a67666c4278a25f732d14e1 100644
--- a/tests/mysql_client_test.c
+++ b/tests/mysql_client_test.c
@@ -20564,7 +20564,6 @@ typedef struct {
 #ifndef EMBEDDED_LIBRARY
 static void test_proxy_header_tcp(const char *ipaddr, int port)
 {
- 
   int rc;
   MYSQL_RES *result;
   int family = (strchr(ipaddr,':') == NULL)?AF_INET:AF_INET6;
@@ -20639,6 +20638,11 @@ static void test_proxy_header_tcp(const char *ipaddr, int port)
     DIE_UNLESS(strncmp(row[0], normalized_addr, addrlen) == 0);
     DIE_UNLESS(atoi(row[0] + addrlen+1) == port);
     mysql_free_result(result);
+    if (i == 0 && !strcmp(ipaddr,"192.0.2.1"))
+    {
+     /* do "dirty" close, to get aborted message in error log.*/
+      mariadb_cancel(m);
+    }
     mysql_close(m);
   }
   sprintf(query,"DROP USER 'u'@'%s'",normalized_addr);