Monday, August 6, 2007

ERROR 2013 (HY000): Lost connection to MySQL server during query

I've got a brand new Ubuntu 7.04 install. I installed MySQL, edited /etc/mysql/my.cnf to allow connections from my local network, but no matter what I did, I always got the following error on trying to connect to the MySQL server from a different machine:

ERROR 2013 (HY000): Lost connection to MySQL server during query

The relevant area of /etc/mysql/my.cnf:

[mysqld]
bind-address = 192.168.0.23

After hours and hours of searching, I found the following solution:


1) /etc/hosts.allow was missing in this version of Ubuntu. You can add them in this way:

sudo apt-get install tcpd

2) I added the following to my new /etc/hosts.allow file:

mysqld: 192.168.0.*


That's it! This now allows me to connect to this MySQL server from any machine on my local network. From what I understand, MySQL on Ubuntu is built with libwrap and that's why you need to edit the /etc/hosts.allow file in this case. I'm no expert, but it worked for me.


The relevant documents are here:

Mysql Docs (see the comments from March 2, 2004)

hosts.allow (useful tips for getting started)

Related:
iptables rule to allow mysql (if you're not an iptables expert)