名为“localhost”的远程数据库服务器的数据库连接字符串 [英] Database connection string for a remote database server named 'localhost'

查看:211
本文介绍了名为“localhost”的远程数据库服务器的数据库连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在机器上设置了远程mysql数据库服务器 myuniversity.edu ,服务器名为' localhost 。在它上面有数据库名为' MyDatabase '。

I have a remote mysql database server setup on a machine myuniversity.edu and server is named 'localhost'. On it I have the database named 'MyDatabase'.

I want to connect it through Java.

The connection urls that I have tried are:
    jdbc:mysql://myuniversity.edu/localhost
    jdbc:mysql://myuniversity.edu/localhost/MyDatabase
    jdbc:mysql://myuniversity.edu:3306/MyDatabase

but I get the `Connection refused: connect` exception.

有人可以告诉你这种情况下连接网址应该是什么?

Could someone please tell what the connection url should be in this case?

推荐答案

好的,这是我做了什么来解决这个问题:

Ok so here's what I did to fix the issue:


  • my.cnf 文件中,我将bind-address从'127.0.0.1'更改为
    'host ipaddress'。这允许连接到远程mysql服务器
    ,但不允许任何尝试连接到
    的远程主机的访问。

  • 为了解决这个问题,我添加了一个条目在主机'%'的用户表中。

  • In my.cnf file, I changed the bind-address from '127.0.0.1' to the 'host ipaddress'. This allows connecting to the remote mysql server but would not allow access for any remote host trying to connect to it.
  • To fix that, I added an entry in user table with host '%'. This allows remote hosts to connect to the database.

现在我可以使用 jdbc:mysql连接到数据库:// serverIpAddress:3306 / MyDatabase

这篇关于名为“localhost”的远程数据库服务器的数据库连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆