In the general case, when opening a connection, a lot of overhead occurs. Depending on how often you expect this to happen, this might be fine, but if you are writing an application that executes more than just a few commands to run a program, I would recommend a connection pool (for server type applications ) or at least one or more connections from your stand-alone application, which should remain open for some time and be reused for several transactions.
Thus, you better control how many connections open at the application level, even before the database server is involved. This is a service that the application server offers, but you can also copy it quite easily if you want to reduce it.
In addition to efficiency considerations, the pool is also a good idea to prepare for demand peaks. When a lot of requests come in, and each of them tries to open a separate database connection - or, as you suggested even more (per transaction), you will quickly run out of resources. Keep in mind that each connection consumes memory inside MySQL!
You also want a non-root user to log in, because if you haven’t done this (I think that it is tied to the MySQL SUPER privilege), you may be blocked. MySQL reserves at least one connection for the administrator to troubleshoot, but if your application connects to this privilege, all connections will already be used when trying to manually turn off the fire.
source share