What do you see if you connect a debug node (displaying the complete msg object) to the ui node you are using?
Exactly which ui node are you using?
How are you building the sql statement now?
Have you tried using a template node (not the ui-template) to build the sql statement?
You should be able to create a small flow where the ui node is connected to a template node which is connected to a debug, What results you get building the sql statement?
Assuming you are using node-red-node-mysql then the terminology in the node config is not particularly good. It refers to a mysql database to connect to when actually it is referring to a mysql server. Each server can itself manage multiple databases.
The database you want to use is specified in the SQL statement but the server you want must (as far as I know) be preselected in the node and cannot be changed at run time.
There may be other mysql nodes that allow the server to be selected at runtime, I don't know.