title: PyMySQL can't connect to MySQL on localhost
body: <p>I'm trying to connect to MySQL on localhost using PyMySQL:</p>
  
  <pre class="lang-py prettyprint-override"><code>import pymysql
  conn = pymysql.connect(db='base', user='root', passwd='pwd', host='localhost')
  </code></pre>
  <p>but (both on Python 2.7 and Python 3.2) I get the error:</p>
  <blockquote>
  <p>socket.error: [Errno 111] Connection refused</p>
  <p>pymysql.err.OperationalError: (2003, &quot;Can't connect to MySQL server on 'localhost' (111)&quot;)</p>
  </blockquote>
  <p>I'm sure mysqld is running because I can connect using <kbd>mysql</kbd> command or phpMyAdmin. Moreover, I can connect using MySQLdb on Python 2 with nearly the same code:</p>
  <pre class="lang-py prettyprint-override"><code>import MySQLdb
  conn = MySQLdb.connect(db='base', user='root', passwd='pwd', host='localhost')
  </code></pre>
  <p>It seems that the problem is on PyMySQL side rather than MySQL but I have no idea how to solve it.</p>