mysql -u userName -p -h hostname
。修改 我不想使用mysql代理,但我的数据库存在于远程服务器上但我的本地机器已连接到互联网抛出Web代理,因此我无法连接到远程数据库服务器。 当我尝试从可以直接访问互联网的机器连接完美工作
1-System - >偏好 - >网络代理。
2- export http_proxy = http:userName:password @ proxyserver:port
但这不起作用。 和帮助将不胜感激..
更新
static {
// SOCKS Proxy
System.setProperty("proxySet", "true");
System.setProperty("socksProxyHost", "proxy-host");
System.setProperty("socksProxyPort", "proxy-port");
System.setProperty("http.proxyHost", "proxy-host");
System.setProperty("http.proxyPort", "proxy-port");
System.setProperty("java.net.socks.username", "username");
System.setProperty("java.net.socks.password", "password");
Authenticator.setDefault(new ProxyAuthenticator("username", "password"));
// 打开网站工作正常
try {
URL url = new URL("http://www.kooora.com/");
URLConnection con = url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(
con.getInputStream()));
// Read it ...
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} catch (IOException iOException) {
iOException.printStackTrace();
}
// 但是打开mysql连接抛出异常
Class.forName("com.mysql.jdbc.Driver").newInstance();
return DriverManager.getConnection(getDBUrl(), USERNAME, PASSWORD);
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.