diff --git a/src/modules/Mysql/acconfig.h b/src/modules/Mysql/acconfig.h
index df028e745844e9a2bbe4f70ec0fa5d2b21cc85cf..0f42472c35884eddc0fed1be9fb46493ed63d1fb 100644
--- a/src/modules/Mysql/acconfig.h
+++ b/src/modules/Mysql/acconfig.h
@@ -58,6 +58,9 @@
 /* Define if your mysql.h defines SHUTDOWN_DEFAULT */
 #undef HAVE_SHUTDOWN_DEFAULT
 
+/* Define if your mysql.h defines MARIADB_CLIENT_VERSION */
+#undef HAVE_MARIADB_CLIENT_VERSION
+
 /* Define if MYSQL_FIELD has a charsetnr member */
 #undef HAVE_MYSQL_FIELD_CHARSETNR
 
diff --git a/src/modules/Mysql/configure.in b/src/modules/Mysql/configure.in
index c43978dc66129aa3dcf78c78dd64f8a133ca6678..4b4e0ec2bb6ad033e175a71facfa2b902e4a8d55 100644
--- a/src/modules/Mysql/configure.in
+++ b/src/modules/Mysql/configure.in
@@ -251,6 +251,8 @@ fi
   AC_CHECK_MYSQL_OPTIONS(MYSQL_OPT_LOCAL_INFILE)
   AC_CHECK_MYSQL_OPTIONS(SHUTDOWN_DEFAULT)
 
+  AC_CHECK_MYSQL_OPTIONS(MARIADB_CLIENT_VERSION)
+
   # Mysql libs
 
 dnl   if test x"$pike_cv_sys_os" = xWindows_NT ; then
@@ -526,6 +528,9 @@ int main(int argc, char *argv[])
     PIKE_CHECK_MYSQL_FUNC(mysql_port)
     PIKE_CHECK_MYSQL_FUNC(mysql_unix_port)
 
+    # MariaDB API functions:
+    PIKE_CHECK_MYSQL_FUNC(mariadb_get_info)
+
     if test "$pike_cv_mysql_mysql_fetch_lengths" = "yes"; then
       #
       # In 3.20.6b mysql_fetch_lengths() returns an uint *.
diff --git a/src/modules/Mysql/mysql.c b/src/modules/Mysql/mysql.c
index e3cb5ac7028db53de480379595828c7aaa44012a..f04e05f3ee6254047262a23406c18dca9b88d6cb 100644
--- a/src/modules/Mysql/mysql.c
+++ b/src/modules/Mysql/mysql.c
@@ -1947,11 +1947,41 @@ static void f_client_info(INT32 args)
 {
   pop_n_elems(args);
 
+#if defined(HAVE_MARIADB_GET_INFO) && defined(HAVE_MARIADB_CLIENT_VERSION)
+  /* MariaDB 10.2 and later (and probably some earlier versions as well). */
+  push_text("MariaDB/");
+  {
+    char *vers = NULL;
+    if (mariadb_get_info(NULL, MARIADB_CLIENT_VERSION, &vers) < 0) {
+      vers = "unknown";
+    }
+    push_text(vers);
+  }
+  f_add(2);
+#else
+#ifndef MYSQL_SERVER_VERSION
+  /* NB: MariaDB 10.2 <mysql/mysql.h> doesn't include this file,
+   *     and also doesn't define MYSQL_SERVER_VERSION.
+   */
+#include <mysql/mysql_version.h>
+#endif
+
 #ifndef MYSQL_COMPILATION_COMMENT
+#ifdef LIBMARIADB
+#define MYSQL_COMPILATION_COMMENT "MariaDB"
+#else
 #define MYSQL_COMPILATION_COMMENT "MySQL (Copyright Abandoned)"
 #endif
+#endif
 
+#ifdef LIBMYSQL_VERSION
+  /* MariaDB 10.2 and later (and probably some earlier versions as well). */
+  push_text(MYSQL_COMPILATION_COMMENT "/" LIBMYSQL_VERSION);
+#else
+  /* Older MySQL and MariaDB. */
   push_text(MYSQL_COMPILATION_COMMENT "/" MYSQL_SERVER_VERSION);
+#endif
+#endif
 }
 
 /*! @endmodule