Skip to content

Commit

Permalink
Merge pull request #1345 from k3yss/work/keys/mysql-root-fix
Browse files Browse the repository at this point in the history
fix: Root user password assignment in MySQL and MariaDB
  • Loading branch information
domenkozar authored Jul 28, 2024
2 parents 0779ee8 + 537cdcb commit 50da41d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/modules/services/mysql.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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`;'
'')
Expand Down

0 comments on commit 50da41d

Please sign in to comment.