远程连接MySQL服务器 [英] Remote Connection to MySQL Server
问题描述
你好,我是MySQL服务器的新手,我想从我的电脑远程数据库远程连接到MySQL数据库!我拥有MySQL服务器的机器上的IP是:
hello there I am new to MySQL Server and I want to connect to MySQL DataBase remotely from my computer other than database placed on! My IP on machine on which I have MySQL server is:
39.32.58.13
我正在使用此代码进行连接:
and I am using this code to connect:
private Connection connect = null;
private Statement statement = null;
private PreparedStatement preparedStatement = null;
private ResultSet resultSet = null;
private void Connect(){
try{
// this will load the MySQL driver, each DB has its own driver
Class.forName("com.mysql.jdbc.Driver");
// setup the connection with the DB.
connect = DriverManager
.getConnection("jdbc:mysql://39.32.222.77:3306/test","myname", "mypass");
}
}
但它总是给我一个错误:
But it gives me an error all the time:
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.
我做错了是因为我是这是第一次这样做,需要有关如何做的说明!所以请不要介意我的错误提前谢谢
Is it me doing something wrong because I'm doing it for the first time and need instructions on how to do it ! so please dont mind my mistakes thanks in advance
推荐答案
您需要授予远程位置使用mysql的权限。
You need to grant permission for using mysql fro remote location.
GRANT ALL PRIVILEGES ON *.* TO 'user'@'%.example.com'
IDENTIFIED BY PASSWORD 'Password'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
其中用户可以是root用户或任何其他用户
where user can be root or any other user
有关授权的更多信息,请参阅此处
see this for more info on grant
这篇关于远程连接MySQL服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!