Home > Back-end >  mysql fetching data from server
mysql fetching data from server

Time:02-13

When get new data from the database, does this mean a new connection? mysql database

Eg:

 SELECT * FROM employees WHERE ID=1

Does this mean a new connection on the database server?

CodePudding user response:

If you are not so familiar with SQL, this is an SQL Query. It is a kind of specifying the requirements of data which you are requesting from the database. Database Connection is a different thing.

I recommend you should dig in to SQL to understand bit more, it is very easy to learn..

CodePudding user response:

Does this mean a new connection on the database server?

  1. If you are already connected then no
  2. If you are not connected then yes
  3. If your connection hit a timeout on no activity, or similar then yes

You can see your connections (as a normal user) using:

show processlist

https://dev.mysql.com/doc/refman/8.0/en/show-processlist.html

You can see the connection ID and if you are looking to see if your connection is changing then that will help.

CodePudding user response:

Do I need a connection to perform a query?

Yes, absolutely.

Do I need a fresh connection to get the latest data?

No, you only need to query again.

Does every query need a new connection?

No, you only need one connection, then you can make several queries. Typically, you open the connection once when starting your program, and then do whatever you need; even closing the db is optional, modern languages do that for you when you exit the script, but it's nice to take care of it when you're done.

  • Related