擅长:python、mysql、java
<p>尝试将<code>"localhost"</code>更改为<code>"127.0.0.1"</code>,它应该可以按预期工作。此行为在<a href="http://mysql-python.sourceforge.net/MySQLdb.html" rel="noreferrer">manual</a>中详细说明:</p>
<blockquote>
<p>UNIX sockets and named pipes don't
work over a network, so if you specify
a host other than localhost, TCP will
be used, and you can specify an odd
port if you need to (the default port
is 3306):</p>
<p><code>db=_mysql.connect(host="outhouse", port=3307, passwd="moonpie", db="thangs")</code></p>
<p>If you really had to, you could
connect to the local host with TCP by
specifying the full host name, or
<strong>127.0.0.1</strong>.</p>
</blockquote>