I'm in an environment where in order to connect to the SQL database, I first need to create a tunnel that redirects the local port to a remote machine.
I connect to a different db server, depending on the port number in the tunnel.
In other words: I always connect to MySql with the same parameters to localhost. The tunnel created beforehand is what defines the server I actually connect to.
There are several MySql servers, all with the same schema (for testing purposes) and I want to know which actual database I'm connected to (my script doesn't have access to the tunnel parameters to know).
When we create a new db, is there a GUID or something that gets attributed to it? Perhaps something I can retrieve with a query to
No, the schema name is the identifier.
You may want to set
server_id uniquely on each of your MySQL instances. This is an integer in the range 1 through 232-1 that you configure in your MySQL instance's
server_id is used to tag changes in the binary log, so replica sets don't replay changes they've already seen.
But you can read the
server_id in any SQL query:
And based on its value, you will know which MySQL instance you're on, assuming you have set every instance's
server_id according to some design so you'll know.