A stupid method that works for me on DataGrip2024 on MacOS
Since I saved the query into consoles, this is the folder to find all stored consoles.
/Users/YOURUSERNAME/Library/Application Support/JetBrains/DataGrip2024.2/consoles
Just need to go through those uuid folders to find the correct console.sql, then use the folder name(uuid) to locate the password you are looking for in the keychain like this example below:
IntelliJ Platform DB — 892a71d8-e6ab-4a3e-9f3c-4ccc0d1bd2e2