0

I'm trying to make a java application that connects to a database that is not located on my pc. I'm not sure how to do this. If I create my own database with MySQL, where do i need to store the database in order to acces it from other computers. I want to know what do I need in order to do this. I checked the internet and saw a lot of examples using jdbc and connecting to a url with localhost or something like this. Thank you!

5
  • 1
    Instead of connecting to localhost, you have to put the remote host name or ip address, That's about it. Commented Mar 25, 2016 at 22:24
  • 1) you need to bind MySQL to the correct interface to allow remote access. 2) you need a user in MySQL that is allowed to connect remotely. 3) you need configure jdbc to connect to you remote server by specifying its IP address rather than localhost. Commented Mar 25, 2016 at 22:33
  • @PeterLawrey And I have to store the database in some place? For example, I create the database on my pc using my local instance from MySQL with localhost3306... How Can I connect to this database from other pc? Where is it stored? Commented Mar 25, 2016 at 22:34
  • Why does it matter where it's stored? MySQL is a server, it runs on a computer and exposes port 3306 for connect (if correctly configured). JDBC on any other computer connects to port 3306. Commented Mar 25, 2016 at 22:37
  • It is stored on your file system, in a directory somewhere, but you don't need to know this to connect to it. You need to replace localhost::3306 with {your-host-name}:3306 Only you know what you hostname is. Commented Mar 25, 2016 at 22:39

1 Answer 1

2

Local: the server address will be 'localhost' or '127.0.0.1' You can install mysql on your computer and connect to it with the computer's ip (generally 192.168.1.??). You can install LAMP or MAMP to have mysql working easily on your network ('put online' option).

Internet: the server adresse is given by your host, replace the 'localhost' or '127.0.0.1' address on the jdbc parameters.

Sign up to request clarification or add additional context in comments.

5 Comments

And do i need a server for that?I don't really understand how does MySQL works. Could you explain the process for me please?I mean, i want to create the database from a pc and then i want to have acces to it from any pc at any given time.
@AlexChihaia MySQL is a server.
The principle of a 'server' is that a 'machine' was running all the time then you can connect to it at any given time, we called this a 'server' (eg a server computer). Then on this machine you can install any program that can handles connection, like 'apache' for HTTP, or 'mysql' for database, these are servers applications (on server computer).
In your case you need a computer that run everyday with mysql installed on it. But to do this at home, you need a static ip address to connect to it from external. it's not the simplest way. Else you can find a host provider that handle all this for you.
@Tokazio Managed to solve the problem. Thanks for your help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.