diff --git a/ChangeLog.md b/ChangeLog.md
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -1,3 +1,9 @@
+## 0.1.3
+
+* Safer concurrency - see https://ro-che.info/articles/2015-04-17-safe-concurrent-mysql-haskell
+* Better support for building against MariaDB (not well tested).
+* Additional C binding: mysql_get_server_version().
+
 ## 0.1.2.1
 
 * Fix bystestring-valued connectOptions sometimes not being null terminated at the correct place (avoid unsafeUseAsCString).
diff --git a/Database/MySQL/Base.hs b/Database/MySQL/Base.hs
--- a/Database/MySQL/Base.hs
+++ b/Database/MySQL/Base.hs
@@ -72,6 +72,9 @@
     -- * General information
     , clientInfo
     , clientVersion
+    -- * Concurrency
+    , initLibrary
+    , initThread
     ) where
 
 import Control.Applicative ((<$>), (<*>))
@@ -176,6 +179,13 @@
     , sslCiphers :: String -- ^ Comma-separated list of cipher names.
     } deriving (Eq, Read, Show, Typeable)
 
+-- | The constructors of @MySQLError@ are not currently exported, but they
+--   have a consistent set of field names which are exported.  These fields are:
+--
+--   >  errFunction :: String
+--   >  errNumber   :: Int
+--   >  errMessage  :: String
+--
 data MySQLError = ConnectionError {
       errFunction :: String
     , errNumber :: Int
@@ -541,6 +551,30 @@
 
 withConn :: Connection -> (Ptr MYSQL -> IO a) -> IO a
 withConn conn = withForeignPtr (connFP conn)
+
+-- | Call @mysql_library_init@
+--
+-- See <https://ro-che.info/articles/2015-04-17-safe-concurrent-mysql-haskell>
+-- for details.
+initLibrary :: IO ()
+initLibrary = do
+  r <- mysql_library_init 0 nullPtr nullPtr
+  if r == 0
+    then return ()
+    else throw $ ConnectionError "initLibrary" (-1)
+      "mysql_library_init failed"
+
+-- | Call @mysql_thread_init@
+--
+-- See <https://ro-che.info/articles/2015-04-17-safe-concurrent-mysql-haskell>
+-- for details.
+initThread :: IO ()
+initThread = do
+  r <- mysql_thread_init
+  if r == 0
+    then return ()
+    else throw $ ConnectionError "initThread" (-1)
+      "mysql_thread_init failed"
 
 withRes :: String -> Result -> (Ptr MYSQL_RES -> IO a) -> IO a
 withRes func res act = do
diff --git a/Database/MySQL/Base/C.hsc b/Database/MySQL/Base/C.hsc
--- a/Database/MySQL/Base/C.hsc
+++ b/Database/MySQL/Base/C.hsc
@@ -25,6 +25,7 @@
     -- ** Connection information
     , mysql_thread_id
     , mysql_get_server_info
+    , mysql_get_server_version
     , mysql_get_host_info
     , mysql_get_proto_info
     , mysql_character_set_name
@@ -63,6 +64,9 @@
     -- * Error handling
     , mysql_errno
     , mysql_error
+    -- * Concurrency
+    , mysql_library_init
+    , mysql_thread_init
     ) where
 
 #include "mysql_signals.h"
@@ -138,7 +142,7 @@
 foreign import ccall safe "mysql.h mysql_options" mysql_options_
     :: Ptr MYSQL -> CInt -> Ptr a -> IO CInt
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_real_connect"
+foreign import ccall safe "mysql_signals.h _hs_mysql_real_connect"
         mysql_real_connect
     :: Ptr MYSQL -- ^ Context (from 'mysql_init').
     -> CString   -- ^ Host name.
@@ -159,26 +163,26 @@
     -> CString                  -- ^ Ciphers.
     -> IO MyBool
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_close" mysql_close
+foreign import ccall safe "mysql_signals.h _hs_mysql_close" mysql_close
     :: Ptr MYSQL -> IO ()
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_ping" mysql_ping
+foreign import ccall safe "mysql_signals.h _hs_mysql_ping" mysql_ping
     :: Ptr MYSQL -> IO CInt
 
 foreign import ccall safe mysql_thread_id
     :: Ptr MYSQL -> IO CULong
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_autocommit" mysql_autocommit
+foreign import ccall safe "mysql_signals.h _hs_mysql_autocommit" mysql_autocommit
     :: Ptr MYSQL -> MyBool -> IO MyBool
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_change_user" mysql_change_user
+foreign import ccall safe "mysql_signals.h _hs_mysql_change_user" mysql_change_user
     :: Ptr MYSQL
     -> CString                  -- ^ user
     -> CString                  -- ^ password
     -> CString                  -- ^ database
     -> IO MyBool
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_select_db" mysql_select_db
+foreign import ccall safe "mysql_signals.h _hs_mysql_select_db" mysql_select_db
     :: Ptr MYSQL
     -> CString
     -> IO CInt
@@ -186,6 +190,9 @@
 foreign import ccall safe mysql_get_server_info
     :: Ptr MYSQL -> IO CString
 
+foreign import ccall safe mysql_get_server_version
+    :: Ptr MYSQL -> IO CULong
+
 foreign import ccall safe mysql_get_host_info
     :: Ptr MYSQL -> IO CString
 
@@ -201,10 +208,10 @@
 foreign import ccall safe mysql_get_ssl_cipher
     :: Ptr MYSQL -> IO CString
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_stat" mysql_stat
+foreign import ccall safe "mysql_signals.h _hs_mysql_stat" mysql_stat
     :: Ptr MYSQL -> IO CString
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_real_query" mysql_real_query
+foreign import ccall safe "mysql_signals.h _hs_mysql_real_query" mysql_real_query
     :: Ptr MYSQL -> CString -> CULong -> IO CInt
 
 foreign import ccall safe mysql_insert_id
@@ -216,13 +223,13 @@
 foreign import ccall safe mysql_affected_rows
     :: Ptr MYSQL -> IO CULLong
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_store_result" mysql_store_result
+foreign import ccall safe "mysql_signals.h _hs_mysql_store_result" mysql_store_result
     :: Ptr MYSQL -> IO (Ptr MYSQL_RES)
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_use_result"  mysql_use_result
+foreign import ccall safe "mysql_signals.h _hs_mysql_use_result"  mysql_use_result
     :: Ptr MYSQL -> IO (Ptr MYSQL_RES)
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_free_result" mysql_free_result
+foreign import ccall safe "mysql_signals.h _hs_mysql_free_result" mysql_free_result
     :: Ptr MYSQL_RES -> IO ()
 
 foreign import ccall safe "mysql.h mysql_free_result" mysql_free_result_nonblock
@@ -243,16 +250,16 @@
 foreign import ccall safe mysql_row_tell
     :: Ptr MYSQL_RES -> IO MYSQL_ROW_OFFSET
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_next_result" mysql_next_result
+foreign import ccall safe "mysql_signals.h _hs_mysql_next_result" mysql_next_result
     :: Ptr MYSQL -> IO CInt
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_commit" mysql_commit
+foreign import ccall safe "mysql_signals.h _hs_mysql_commit" mysql_commit
     :: Ptr MYSQL -> IO MyBool
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_rollback" mysql_rollback
+foreign import ccall safe "mysql_signals.h _hs_mysql_rollback" mysql_rollback
     :: Ptr MYSQL -> IO MyBool
 
-foreign import ccall unsafe "mysql_signals.h _hs_mysql_fetch_row" mysql_fetch_row
+foreign import ccall safe "mysql_signals.h _hs_mysql_fetch_row" mysql_fetch_row
     :: Ptr MYSQL_RES -> IO MYSQL_ROW
 
 foreign import ccall safe "mysql.h mysql_fetch_row" mysql_fetch_row_nonblock
@@ -276,3 +283,9 @@
 
 foreign import ccall safe mysql_error
     :: Ptr MYSQL -> IO CString
+
+foreign import ccall safe "mysql.h mysql_server_init" mysql_library_init
+    :: CInt -> Ptr (Ptr Char) -> Ptr (Ptr Char) -> IO CInt
+
+foreign import ccall safe "mysql.h" mysql_thread_init
+    :: IO MyBool
diff --git a/Setup.hs b/Setup.hs
--- a/Setup.hs
+++ b/Setup.hs
@@ -8,8 +8,8 @@
 #define MIN_VERSION_Cabal(x,y,z) 0 
 #endif
 
-import Control.Monad (liftM2, mplus)
-import Data.List (isPrefixOf)
+import Control.Monad (liftM, msum, sequence)
+import Data.List (isPrefixOf, nub)
 import Distribution.PackageDescription
 import Distribution.Simple
 import Distribution.Simple.LocalBuildInfo
@@ -41,13 +41,17 @@
 }
 
 mysqlConfigProgram = (simpleProgram "mysql_config") {
-    programFindLocation = \verbosity -> constOrId $ liftM2 mplus
+    programFindLocation = \verbosity -> constOrId $ liftM msum $ sequence
 #if MIN_VERSION_Cabal(1,24,0)
-      (findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mysql_config")
-      (findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mysql_config5")
+      [ (findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mysql_config")
+      , (findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mysql_config5")
+      , (findProgramOnSearchPath verbosity [ProgramSearchPathDefault] "mariadb_config")
+      ]
 #else
-      (findProgramLocation verbosity "mysql_config")
-      (findProgramLocation verbosity "mysql_config5")
+      [ (findProgramLocation verbosity "mysql_config")
+      , (findProgramLocation verbosity "mysql_config5")
+      , (findProgramLocation verbosity "mariadb_config")
+      ]
 #endif
   }
 
@@ -58,10 +62,13 @@
 
   include <- mysqlConfig ["--include"]
   libs <- mysqlConfig ["--libs"]
+  libsR <- mysqlConfig ["--libs_r"]
 
   return emptyBuildInfo {
     extraLibDirs = map (drop 2) . filter ("-L" `isPrefixOf`) $ libs
   , extraLibs = map (drop 2) . filter ("-l" `isPrefixOf`) .
-                filter (/= "-lmygcc") $ libs
+                filter (/= "-lmygcc") $
+                filter (/= "-lmysqlclient_r") $
+                nub (libs ++ libsR)
   , includeDirs = map (drop 2) include
   }
diff --git a/mysql.cabal b/mysql.cabal
--- a/mysql.cabal
+++ b/mysql.cabal
@@ -1,5 +1,5 @@
 name:           mysql
-version:        0.1.2.1
+version:        0.1.3
 homepage:       https://github.com/paul-rouse/mysql
 bug-reports:    https://github.com/paul-rouse/mysql/issues
 synopsis:       A low-level MySQL client library.
