MySQL: Single or Multiple Connections?

2019-06-07 07:30发布

问题:

I am developing a server application, which uses mysql for some data storing. Should I create a connection to the mysql on the server's start and use it for all queries, or create connection on each query? Which is better/faster?

回答1:

If you ask me, It's better to use only one connection, that way you can use session variables without any issues. Besides, with static variables, it's easy to permanently save the connection somewhere in the script.