简体   繁体   English

mysql连接到主机

[英]mysql connecting to host

we are trying to connect to the host using the code shown below: 我们正在尝试使用下面显示的代码连接到主机:

 Connection con=null;
             try {
                 Class.forName("com.mysql.jdbc.Driver");
                    con=DriverManager.getConnection("jdbc:mysql://sql3.000webhost.com/a17644_cc","chat_cc",                       "pass");          
                 ResultSet rs;
                 if(!con.isClosed())
                 {
                Statement st = con.createStatement();

                  rs= st.executeQuery("SELECT * FROM  user_info");
                 while(rs.next()){
                    t1.append(rs.getString(3));
                 }
                 }
               } catch(Exception e) {
                   t1.setText(e.toString());
                 //e.printStackTrace();
               } finally {
                 try {
                   if(con != null)
                     con.close();
                 }catch (java.sql.SQLException e) {
                    // TODO Auto-generated catch block
                    //e.printStackTrace();
                     t1.setText(e.toString());
                }

we have given internet permission also in the manifest file. 我们在清单文件中也授予了Internet许可。

But getting the following error: 但是出现以下错误:

java.sql.exception: data source rejected establishment of connection , message from server:" Host '182.71.248.226. is not allowed to connect to this MySQL server " java.sql.exception: 数据源拒绝建立连接 ,来自服务器的消息:“ 主机'182.71.248.226。不允许连接到该MySQL服务器

This is the following details i got: please tell which name we must give in the connection string Domain chitchat.site90.net Username a1740644 Password * 这是我得到的以下详细信息:请在连接字符串中告诉我们必须指定的名称域chitchat.site90.net用户名a1740644密码* Disk Usage 0.14 / 1500.0 MB Bandwidth 100000 MB (100GB) Home Root /home/a1740644 Server Name server19.000webhost.com IP Address 31.170.160.83 Apache ver. 磁盘使用率0.14 / 1500.0 MB带宽100000 MB(100GB)主目录根/ home / a1740644服务器名称server19.000webhost.com IP地址31.170.160.83 Apache ver。 2.2.19 (Unix) PHP version 5.2. 2.2.19(Unix)PHP版本5.2。 MySQL ver. MySQL版本 5.1 Activated On 2012-05-01 02:14 Status Active 5.1于2012-05-01 02:14激活状态有效

That error is telling you that the user does not have rights to connect and select the database. 该错误告诉您用户无权连接和选择数据库。 You need to either grant rights to all hosts, or hosts from the specific IP address you are using. 您需要授予所有主机的权限,或者授予所用特定IP地址的主机的权限。 To grant to all hosts, you'd have to issue this as an administrative user: 要授予所有主机,您必须以管理用户身份发出此命令:

GRANT ALL ON a17644_cc.* TO 'chat_cc'@'%'

or alternatively 或者

GRANT ALL ON a17644_cc.* TO 'chat_cc'@'182.71.248.226'

Assuming that the IP in question is static, and you want to constrain the connection by IP. 假设所讨论的IP是静态的,并且您想通过IP限制连接。

As pointed out by https://stackoverflow.com/a/1559992/700926 this is probably a security precaution. https://stackoverflow.com/a/1559992/700926所指出,这可能是安全预防措施。 Check out the accepted answer to that question. 查看该问题的可接受答案。

MySQL服务器的端口号是多少?

除了gview的答案之外,您还可以在MySQL Workbench中设置权限。导航到“安全性->用户和特权”。

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

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