diff --git a/scripts/mysql_config.sh b/scripts/mysql_config.sh
index 86cbe944416d15fc1744bd043c1381f536226e49..90418de3d1dbc392eb8513c124b2e6478914857a 100644
--- a/scripts/mysql_config.sh
+++ b/scripts/mysql_config.sh
@@ -88,7 +88,7 @@ client_libs='@CLIENT_LIBS@'
 
 libs="$ldflags -L$pkglibdir -lmysqlclient $client_libs"
 libs=`echo "$libs" | sed -e 's;  \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
-libs_r="$ldflags -L$pkglibdir -lmysqlclient_r @LIBS@ @openssl_libs@"
+libs_r="$ldflags -L$pkglibdir -lmysqlclient_r @LIBS@ @ZLIB_LIBS@ @openssl_libs@"
 libs_r=`echo "$libs_r" | sed -e 's;  \+; ;g' | sed -e 's;^ *;;' | sed -e 's; *\$;;'`
 cflags="-I$pkgincludedir @CFLAGS@ " #note: end space!
 include="-I$pkgincludedir"
@@ -100,7 +100,9 @@ for remove in DDBUG_OFF DSAFEMALLOC USAFEMALLOC DSAFE_MUTEX \
               DPEDANTIC_SAFEMALLOC DUNIV_MUST_NOT_INLINE DFORCE_INIT_OF_VARS \
               DEXTRA_DEBUG DHAVE_purify 'O[0-9]' 'W[-A-Za-z]*'
 do
-  cflags=`echo "$cflags"|sed -e "s/-$remove  *//g"` 
+  # The first option we might strip will always have a space before it because
+  # we set -I$pkgincludedir as the first option
+  cflags=`echo "$cflags"|sed -e "s/ -$remove  */ /g"` 
 done
 cflags=`echo "$cflags"|sed -e 's/ *\$//'`