Remote connection to MySQL server

Hi,

I have two small VPS servers (they’re clean, I haven’t installed control panels yet so I wanted to ask it rather than spending a few hours) and I’ll create two db connections to the dedicated server using remote connection with PHP.

I’ll be performing inserts, updates and deletes on the dedicated server. I haven’t tried something like this before and I am worried that there may be a mix-up with my database records since I’ll be connecting from two different places. Is there a way to create something like “session” that’s unique to that machine so my records won’t mix up with each other (I run select queries to get the last inserted ID) ?

I can create a fake column in the db that states which is which (vps1 - vps2) so I could get the highest value of vps1/vps2, but I thought I should ask.

What kind of mix-up are you expecting? MySQL is designed for multiple concurrent connections and two different places is not much. Of course, if you do updates on the same rows from two places at the same time you may expect problems so you need to handle that but I’m not sure what your use case is going to be.

LAST_INSERT_ID is separate for each session (connection) so they won’t clash - MySQL creates the session for each connection so you don’t have to do anything about it.

1 Like

I didn’t know that. Thank you!

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.