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.
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)
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.