Recent

Author Topic: Access MySQL database from across the Internet?  (Read 1153 times)

Cillchaoi

  • Newbie
  • Posts: 5
Access MySQL database from across the Internet?
« on: June 09, 2022, 04:42:13 pm »
I am brand new to Lazarus and will start playing around with it this weekend so as to get familiar with the environment.  However, one big question I have is whether it is possible to connect to and work with a MySQL database that is stored on my website's webhosting server.  I do not have the database here locally, of course: it is stored on one of their servers wherever the blazes it is.

I realize that the answer may vary from one hosting service to another, so I am asking whether anyone has had success with doing this or if this is typically not permitted due to server security issues or whatever else.

Any insight, advice, and other commentary that you all can offer will be greatly appreciated.

MarkMLl

  • Hero Member
  • *****
  • Posts: 8574
Re: Access MySQL database from across the Internet?
« Reply #1 on: June 09, 2022, 09:30:57 pm »
I realize that the answer may vary from one hosting service to another, so I am asking whether anyone has had success with doing this or if this is typically not permitted due to server security issues or whatever else.

Any insight, advice, and other commentary that you all can offer will be greatly appreciated.

Speak to your service provider. Don't even dream of doing it if the connection isn't encrypted, and even then expect problems from people probing it once they've noticed the open port.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Zvoni

  • Hero Member
  • *****
  • Posts: 3435
Re: Access MySQL database from across the Internet?
« Reply #2 on: June 10, 2022, 08:20:30 am »
What Mark said.
Though to the original Question: I have done something like this for testing purposes.
As long as you open the/a port (it doesn't have to be the Default 3306-Port) and any traffic to this "visible" port gets relayed correctly it works without Problems.
Security reasons as stated by Mark not withstanding
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

dseligo

  • Hero Member
  • *****
  • Posts: 1686
Re: Access MySQL database from across the Internet?
« Reply #3 on: June 10, 2022, 11:14:56 am »
If you use shared hosting then look for 'SSH access' or something similar in hosting's Control panel. You can make SSH tunnel to your web hosting this way, I used this several times.
I just tried with my website's hosting and it works.

I did the following:
- create SSH keys (in my cPanel: Security, SSH Access, Manage SSH Keys, Generate a New Key). Create strong password for your key. I converted key to PPK format so I can use it with Putty. Download private key. I also had option to upload my own key.

- set up tunnel on your computer. I use Windows, so I created new session in Putty (https://www.putty.org/):
  - in Connection/SSH/Tunnels add new forwarded port (source 3307 because I have MariaDB installed locally, destination 'localhost:3306').
  - under SSH/Authentication you browse for private key you downloaded.
  - in SSH check 'Enable compression' and 'Don't start a shell or command at all'.
  - in Connection/Data enter your username in 'Auto-login username'
  - in Session enter host name and name for your session in 'Saved sessions'
  - click Save

Now you can open tunnel in Putty (you need to provide password for private key).

After tunnel is open, you access mySQL on your web server by connecting to local host, to port you set as 'source' in Putty, and with database name, user and password as you set in your web control panel.

Of course, I think that for developing and testing, it would be easier if you install mySQL server on your computer. After you are done testing, just change connection parameters.

HTH

MarkMLl

  • Hero Member
  • *****
  • Posts: 8574
Re: Access MySQL database from across the Internet?
« Reply #4 on: June 10, 2022, 11:50:14 am »
If you use shared hosting then look for 'SSH access' or something similar in hosting's Control panel. You can make SSH tunnel to your web hosting this way, I used this several times.

I agree, and I was just about to expand on my original answer to that effect. However that /still/ requires that the service provider make SSH available (which he might not, if the only permitted access is via a web interface) and SSH on the standard port will attract a vast amount of probe traffic (ask me how I know).

Something like SSH can, of course, be protected by "port knocking", /but/ at that point you're getting sufficiently deep into host configuration that you might find it falls foul of any other attempts to be clever: containerisation, tunelling, VLANs and so on.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Logitech, TopSpeed & FTL Modula-2 on bare metal (Z80, '286 protected mode).
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

 

TinyPortal © 2005-2018