我需要使用远程mysql服务器访问数据库,但是当我尝试它时,我收到这样的错误:
SQLException: Access denied for user 'u121252012_iya'@'114.79.63.156' (using password: YES)
SQLState: 28000
VendorError: 1045
这是我的连接代码:
package Include;
import java.sql.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
/**
*
* @author Ruslan
*/
public class Koneksi {
private static Connection koneksi;
public static void main (String []args){
Connection conn = null;
try {
conn =
DriverManager.getConnection("jdbc:mysql://my_ip_server/u121252012_coba?" +
"user=u121252012_iya&password=qwertyu");
// Do something with the Connection
} catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
}
}
拜托,我需要您的帮助来解决它。
答案 0 :(得分:0)
CREATE USER '<username>'@'%' IDENTIFIED BY '<pwd>';
此处%表示允许用户从所有IP进行访问。 此外,您可能还需要向用户授予权限
GRANT ALL PRIVILEGES ON *.* TO '<username>'@'%' WITH GRANT OPTION;
而且,连接机制应该是这样的。
conn = DriverManager.getConnection(<DB_URL>,<USER>,<PASS>);
所以改变
conn =
DriverManager.getConnection("jdbc:mysql://my_ip_server/u121252012_coba?" +
"user=u121252012_iya&password=qwertyu");
到
conn =
DriverManager.getConnection("jdbc:mysql://my_ip_server/u121252012_coba?",
"u121252012_iya","qwertyu");