diff --git a/src/freedombone-utils-database b/src/freedombone-utils-database
index 37a22bb7f6c1bfec348bbc37aadd82f2df10ab7f..b1f8b84ad8330bf9357dd11e918be229d7fa82cb 100755
--- a/src/freedombone-utils-database
+++ b/src/freedombone-utils-database
@@ -144,6 +144,24 @@ function get_mariadb_password {
     fi
 }
 
+function mariadb_fix_authentication {
+    # See http://www.pontikis.net/blog/debian-9-stretch-rc3-web-server-setup-php7-mariadb
+    # https://mariadb.com/kb/en/mariadb/unix_socket-authentication-plugin
+    function_check run_query
+    run_query_root mysql "update mysql.user set plugin = '' where User='root'; flush privileges;"
+    run_query_root mysql "UPDATE user SET Password=PASSWORD('$MARIADB_PASSWORD') where USER='root'; flush privileges;"
+
+    sed -i 's| --skip-grant-tables||g' /lib/systemd/system/mariadb.service
+    systemctl daemon-reload
+    systemctl restart mariadb
+}
+
+function mariadb_create_root_user {
+    run_query mysql "CREATE USER 'root@localhost' IDENTIFIED BY '${MARIADB_PASSWORD}'; flush privileges;"
+    run_query mysql "update mysql.user set plugin = '' where User='root@localhost'; flush privileges;"
+    run_query mysql "GRANT ALL PRIVILEGES ON * TO 'root@localhost'; flush privileges;"
+}
+
 function install_mariadb {
     if [[ $(is_completed $FUNCNAME) == "1" ]]; then
         return
@@ -151,6 +169,8 @@ function install_mariadb {
     apt-get -yq install software-properties-common debconf-utils
     apt-get -yq update
 
+    remove_watchdog_daemon mariadb
+
     function_check get_mariadb_password
     get_mariadb_password
     if [ ! $MARIADB_PASSWORD ]; then
@@ -185,24 +205,13 @@ function install_mariadb {
     systemctl daemon-reload
     systemctl restart mariadb
 
-    # See http://www.pontikis.net/blog/debian-9-stretch-rc3-web-server-setup-php7-mariadb
-    # https://mariadb.com/kb/en/mariadb/unix_socket-authentication-plugin
-
-    function_check run_query
-    run_query_root mysql "update mysql.user set plugin = '' where User='root'; flush privileges;"
-    run_query_root mysql "UPDATE user SET Password=PASSWORD('$MARIADB_PASSWORD') where USER='root'; flush privileges;"
-
-    sed -i 's| --skip-grant-tables||g' /lib/systemd/system/mariadb.service
-    systemctl daemon-reload
-    systemctl restart mariadb
+    mariadb_fix_authentication
 
     # mariadb daemon seems to occasionally crash
     # This is a crude attempt to keep it running
     add_watchdog_daemon mariadb
 
-    run_query mysql "CREATE USER 'root@localhost' IDENTIFIED BY '${MARIADB_PASSWORD}'; flush privileges;"
-    run_query mysql "update mysql.user set plugin = '' where User='root@localhost'; flush privileges;"
-    run_query mysql "GRANT ALL PRIVILEGES ON * TO 'root@localhost'; flush privileges;"
+    mariadb_create_root_user
 
     mark_completed $FUNCNAME
 }