简体   繁体   中英

PHP MySql unknown server host

I am running Ubuntu 12.04.4 LTS with MySQL 5.5.38 and PHP 5.3.10, using Webmin 1.680 (although I do use the terminal for administration as well). I am on a dynamic IP so I have been using dyndns to host a website, which has been working flawlessly. I want to expand my website to access a mysql database. I am attempting to use PHP to connect to mysql, specifically a specific database I set up using Webmin. However, I keep getting the error:

"Unknown MySQL server host '127.0.0.1:3306'"

I have checked the mysql configuration and it is set to that IP and port. I have also checked my server hosts and that IP is the local host. My router is set to forward port 3306 to my server. This happens whether I connect locally or remote. I am connecting with the following PHP string:

$link = mysqli_connect("127.0.0.1:3306", "username", "password", "dbname");

The solutions I have found in my quest, which do not work... changing the host in the connection string to "localhost:3306" or to my dyndns host name "XYZ.dyndns.org:3306", or to my server's local IP - and changing the mysql binding address to match. I have tried commenting out the binding address in the config file. I have found similar questions asked on this forum and others but none have a solution that works for me. I am new to databases but have done a lot of research on using PHP to manipulate them, I just can't get past this connection error. I have been self-teaching how to run a server and have been able to figure out every problem myself up until this one. I can log into mysql from the terminal on my server but executing the "show databases" command it doesn't list the database I created through webmin, even though I the user to have full access/control of that database.

I had a similar issue when I started out using mysqli. If you need to include the port, it has its own place in mysqli_connect .

$link = mysqli_connect("127.0.0.1", "username", "password", "dbname", 3306);

should work better for you. But I believe 3306 is the default port, so you may be able to just leave it off.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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