title: Why can Wordpress suddenly connect to the MySQL database server once I update the host from "localhost" to "mydomain.com"?
body: <p>This is a specific variation on the "can't connect" problem.  In my case, I've just set up two virtual hosts in my httpd.conf listening on port 80.  The declaration looks like:</p>
  
  <pre>
  NameVirtualHost *:80
  
  &lt;VirtualHost *:80&gt;
      ServerName site1.dev
      DocumentRoot /www/site1
  &lt;/VirtualHost>
  
  &lt;VirtualHost *:80&gt;
      ServerName site2.dev
      DocumentRoot /www/site2
  &lt;/VirtualHost&gt;
  </pre>
  
  <p>So from my understanding, <a href="http://localhost" rel="nofollow noreferrer">http://localhost</a> and <a href="http://site1.dev" rel="nofollow noreferrer">http://site1.dev</a> now both map to "/www/site1/" and of course <a href="http://site2.dev" rel="nofollow noreferrer">http://site2.dev</a> maps to its directory.</p>
  
  <p>This is all well and good.  I have a Wordpress installation I'm playing with currently under the site2.dev domain.  I'm trying to configure it to work with the MySQL database I just set up which has an account "mysql" for "localhost."  So in the configuration for Wordpress, I put in that username and the host name as "localhost."  This doesn't work, so after playing with it for a while, I try changing the host name to "site2.dev" and suddenly it works fine.</p>
  
  <p>What's going on here?  I understand that my virtual hosts are setup, but I thought they were listening on port 80, not port 3306, which is what MySQL uses, so why does any of that matter?  I'm sure there's a simple explanation, so hopefully someone can enlighten me.</p>