1

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
th182
  • 13
  • 1
  • 4
  • 2
    I must commend you for your post because you explained yourself very well. While I'm not totally familiar with an Ubuntu server I've used XAMPP in the past on my Windows computer. I always just left out the port. No portforwarding required if you are running your server locally. You may also try `localhost` in place of `127.0.0.1`. – Nicolas Aug 04 '14 at 17:24
  • r u getting any error messages – fortune Aug 04 '14 at 17:33
  • Can you login in MySQL and provide the output of `SHOW GRANTS \G` (you should remove the password hashes)? – Salem Aug 04 '14 at 17:38
  • I moved the port from the host to the end as indicated in the answer below and got an Access Denied for my username@localhost. Should note that I am using basic authentication for my server and it seems to have taken my username for that rather than the mysql one I put in the connection string. I created a user in mysql with the same name and password as my login one and still denied. – th182 Aug 04 '14 at 18:10
  • Sorry.. output of 'SHOW GRANTS \G is GRANT USAGE ON *.* TO ''@'localhost'' – th182 Aug 04 '14 at 18:11

1 Answers1

1

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.

Don't Panic
  • 41,125
  • 10
  • 61
  • 80
  • Thanks for the reply! It seems to have brought me closer, I not longer get the host error, instead I am getting access denied by the user@localhost (Using password YES) – th182 Aug 04 '14 at 18:14
  • THANK YOU ALL! I was able to grant permissions for my user and now it all works! I appreciate all the help! – th182 Aug 04 '14 at 18:49