title: Can't connect to local MySQL server through socket (From time to time)
body: <p>I have a LAMP stack setup. Occasionally, I get the following error message when I open some page from the browser: </p>
  
  <pre><code>Error creating the connection!: SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  </code></pre>
  
  <p>I think the server was configured correctly. The problem happens about every two months. Every time when I reboot the Linux server, or restart mysql, the problem was gone. I want to fix this problem permanently. Can anyone give me some idea? </p>
  
  <p>Much appreciated. </p>
  
  <h2>EDIT</h2>
  
  <p>The problem occurs again and I checked the mysqld.sock file, it was not there. Do you have any idea how to fix the problem? – Ryan Jul 23 at 16:24</p>