I'm trying to make a query from cmd that return 0 if database exists or any other number (for example 1), if it doesn't.
I make the query in this way:
"C:\mysql.exe" --host=localhost --user=root --password=pass --execute="SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = 'DB_Name'"
If exists, it returns a table (and a exit code 0); if it doesn't, it returns nothing (and a exit code 0 too)
I use this on a Inno Setup installer like:
Exec(
ExpandConstant('{tmp}\mysql.exe'),
'--host='+eServer.text+' --user='+eUser.text+' --password='+ePass.text+
' --port='+ePort.text+
' --execute="SELECT SCHEMA_NAME FROM INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = '+
''''+eDBname.text+''''+'"', '', SW_HIDE, ewWaitUntilTerminated, ResultCode);
if (ResultCode <> 0) then
MsgBox('Error when connecting to server', mbError, MB_OK);
So it returns me 0 even if the database doesn't exist.
--database "dbname"to the arguments? Untested for the moment, but that should fail if the db isn't there, otherwise the query will execute normally.--executeand works