MySQL system error: 111

I’m getting the following error in PHP scripts when run in Ubuntu Linux only when running the MySQL server under Linux:

( ! ) Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at ‘reading initial communication packet’, system error: 111 in /mnt/www/phpfun/mq_orderby.php on line 34

This is my development machine, so I don’t have connection issues. This was working.

Things I’ve tried:

phpMyAdmin works fine.
If I point to another MySQL server, it works fine.
I’ve tried referring to the MySQL server as localhost, blix, and by IP address: 10.0.2.15.

It’s a really simple script too.

I’ll try that.

You can also disable Bind to Ip, so the MySQL server answer both LAN and WAN.

Its important to configure the accounts allowed hosts too. Specially the admin account (root in my case).

In the server configuration, look for “Bind to IP”.
(I use MySQL Workbench)
In a fresh install here (Ubuntu) it’s binded to 127.0.0.1 (localhost).
To fix the problem bind to the IP visible to the LAN or WAN.
Mine is 192.168.0.1 (LAN)

Update: localhost works (only), but 10.0.2.15 doesn’t work for MySQL in PHP.

It DOES work in phpMyAdmin and the CLI:

mysql -u root -p

In CLI I can perform queries.

Oh, forgot. I cannot use localhost because I use a shared .ini file to get the database server from. It is shared between VirtualBox host OS and guest OS. The domain ‘localhost’ would cause PHP applications running on different OSes to cause each OS to look for it in a relative domain, their own. Since there’s only one set of database files, there can only be one database server up and running at a time. For this reason, the domain must be an absolute one.

Update:

I get an error:

mysql -h10.0.2.15 -p
ERROR 2003 (HY000): Can’t connect to MySQL server on ‘10.0.2.15’ (111)

But, mysql -p works.