diff --git a/src/modules/services/mysql.nix b/src/modules/services/mysql.nix index 32e99bf0c..4a761f2f3 100644 --- a/src/modules/services/mysql.nix +++ b/src/modules/services/mysql.nix @@ -114,7 +114,12 @@ with lib; let ${concatMapStrings (user: '' echo "Adding user: ${user.name}" ${optionalString (user.password != null) "password='${user.password}'"} - ( echo "CREATE USER IF NOT EXISTS '${user.name}'@'localhost' ${optionalString (user.password != null) "IDENTIFIED BY '$password'"};" + ( + if [ "${user.name}" = "root" ] && [ -n ${user.password} ]; then + echo "ALTER USER 'root'@'localhost' IDENTIFIED BY '$password';" + else + echo "CREATE USER IF NOT EXISTS '${user.name}'@'localhost' ${optionalString (user.password != null) "IDENTIFIED BY '$password'"};" + fi ${concatStringsSep "\n" (mapAttrsToList (database: permission: '' echo 'GRANT ${permission} ON ${database} TO `${user.name}`@`localhost`;' '')