33

When we say we have a "database connection" or a "connection pool that has several connections open", on the technical level, what are we meaning actually?

My understanding is:

A database connection is a link to a thread running in the database process that is blocked and waiting for an input from another thread in another process.

Is this the right definition?

So when I have MySQL running on a computer and a Java application running on some other computer (or same computer; it does not really matter..) and when I do something like:

conn.open();

to open a database connection...

Will the MySQL process create a new thread for me and block that thread and start listening for input?

What about the client side? What happens if I do not close the connection?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Koray Tugay
  • 22,894
  • 45
  • 188
  • 319
  • 1
    The term connection has a wide variety of meanings. It can refer to a physical or logical path between two entities, it can refer to the flow over the path, it can inferentially refer to an action associated with the setting up of a path, or it can refer to an association between two or more entities, with or without regard to any path between them. Vint Cerf and Bob Kahn, A Protocol for Packet Network Intercommunication – Koray Tugay Aug 02 '18 at 02:03
  • In Packet Switching, there are no connections. What you call a connection is a consensual illusion between two end points. Stuart Cheshire – Koray Tugay Dec 06 '18 at 16:06
  • Koray, i don’t thing such explanation of connection is required for this question. – Rahul Mar 12 '23 at 10:40

1 Answers1

9

Here is a short, but nice socket tutorial.

You have to distinguish the client and server side. I cannot tell for MySQL, but typically the server side is implemented so, that for a connection, a new thread is processing the requests.

A connection pool is there to minimize socket opening overhead. Typically, you do not care via which connection (assuming all connected as the same user); you received the result set from database.

You do not want to consume resources, so you want to be nice and when you are finished you close your connection. I believe every server today ends a connection if there isn't any activity for some time (timeout).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Betlista
  • 10,327
  • 13
  • 69
  • 110