简体   繁体   English

连接远程数据库的问题

[英]Problem with connecting to a remote database

I want to access to a remote database(Mysql),but always an error occure: what it can be the error?我想访问远程数据库(Mysql),但总是发生错误:可能是什么错误?

try{
Class.forName("com.mysql.jdbc.Driver");         
String url = "jdbc:mysql://@IP:3306/jira313";
String user = "jirauser";
String passwd = "jirauser";
Connection conn = DriverManager.getConnection(url, user, passwd);
}catch (Exception e) {
e.printStackTrace();
 }

The error is:错误是:

java.sql.SQLException: Access denied for user 'jirauser'@'MyIP' (using password: NO)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1055)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3491)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3423)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:910)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:3923)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1273)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2031)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:718)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:302)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:282)
at java.sql.DriverManager.getConnection(DriverManager.java:582)
at java.sql.DriverManager.getConnection(DriverManager.java:185)
at javaapplication1.connexion.main(connexion.java:29)

The answer to your question is in your exception:你的问题的答案是你的例外:

java.sql.SQLException: Access denied for user 'jirauser'@'MyIP' (using password: NO)

Log onto the database, if you have access and try:登录到数据库,如果您有权访问并尝试:

GRANT ALL ON YOUR_DATABASE.* TO jirauser@'YOUR_IP' IDENTIFIED BY 'YOUR_PASSWORD';

Your user might be local, first try with mysql client.您的用户可能是本地用户,首先尝试使用 mysql 客户端。 If it also gives error modify user rights to be able to connect from remote.如果它也给出错误修改用户权限,以便能够从远程连接。

Check your code, error says that password is not specified.检查您的代码,错误提示未指定密码。

You don't have the rights to access the remote mysql server.您无权访问远程 mysql 服务器。 Go on the server, log in to MySql and run GRANT ALL PRIVILEGES ON *.* TO 'jirauser'@'%' (this will give you full access -> you should read about privileges first and add the just the privileges you need adding users to MySql Go 在服务器上,登录到 MySql 并运行GRANT ALL PRIVILEGES ON *.* TO 'jirauser'@'%' (这将为您提供完全访问权限 -> 您应该先阅读有关权限并添加您需要添加的权限用户到 MySql

Setup mysql to allow remote connection for the user.设置 mysql 以允许用户进行远程连接。

grant <permission> on <database> to <user>@<location> identified by <password>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM