Unknown MySQL server host

前端 未结 5 1049
Happy的楠姐
Happy的楠姐 2021-02-04 04:08

When trying to connect to my database server, i encounter the problem of unknown host:

Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2005):          


        
相关标签:
5条回答
  • 2021-02-04 04:36

    If you use this code:

    $Mysqli= new mysqli('mysql2.servidoreswindows.net:3306',
                        'usu', 'pass', 'dbname');
    

    you can try to write host without port

    That is:

    $Mysqli= new mysqli('mysql2.servidoreswindows.net', 'usu', 'pass', 'dbname');
    
    0 讨论(0)
  • 2021-02-04 04:38

    Please pay attention with AWS security groups:

    In my case I can connect to RDS from my computer throw Telnet and I can connect throw Mysql Workbench also but I cant connect from my EC2 instance that is within the same VPC as the RDS.

    The solution was:
    1. I have created a security group (exampl1) for RDS and assigned to it.
    2. I have created a security group (exampl2) for EC2 and assigned to it.
    and I have assigned the RDS security group (exampl1) to the EC2 too. << this saves me.

    Info: If your EC2 has assigned 2 or more security groups, then in the RDS security group inbound source has to create rules as many security groups has your EC2 assigned.

    Amazon docs says:
    The EC2 instance in the VPC shares the same VPC security group with the DB instance. http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html

    I spent all day searching docs.
    I hope this help you.

    0 讨论(0)
  • 2021-02-04 04:38

    I know this is an old question. But I ran into this same issue today, and none of the answers I found were the right one.

    The issue in my case ended up being that port 3306 is not open on our firewall, and I was attempting to connect to an internal mysql database from an external server.

    I'm not sure why the error it gives you is "Unknown Host" in this case. I would have expected something more like "Unable to connect." or "Connection refused.", but using the exact same code from an internal server worked fine, leading me to this conclusion.

    0 讨论(0)
  • 2021-02-04 04:40

    Make sure you're not including the "http://" part. I was using http://example.com in my .env file. When I left it as example.com it worked.

    0 讨论(0)
  • 2021-02-04 04:41

    This is usually the case when name resolving doesn't work on the host. If your connect destination is always the same, you might want to use its IP address for connecting instead.

    0 讨论(0)
提交回复
热议问题