How to connect to a remote MySQL database with Java?

后端 未结 8 1456
暗喜
暗喜 2020-12-02 11:16

I am trying to create a JSF application using the Eclipse IDE. I am using a remote mySQL server as my database. How do I connect to this remote database for creating tables

8条回答
  •  我在风中等你
    2020-12-02 12:01

    Just supply the IP / hostname of the remote machine in your database connection string, instead of localhost. For example:

    jdbc:mysql://192.168.15.25:3306/yourdatabase
    

    Make sure there is no firewall blocking the access to port 3306

    Also, make sure the user you are connecting with is allowed to connect from this particular hostname. For development environments it is safe to do this by 'username'@'%'. Check the user creation manual and the GRANT manual.

提交回复
热议问题