Remote MySQL connection works from cmdline, but not with Apache (Webpy, Mod-WSGI)
<ul>
<li>Server OS: Red Hat Enterprise Linux Server release 5.11 </li>
<li>Apache: 2.2.3</li>
<li>Python: 2.7.6</li>
<li>Mod_WSGI 4.5.3, Web.Py, MySQLdb</li>
</ul>

<p>Hey! I have created a Web.Py site that queries data from a remote Oracle database which works perfectly, but I have now run into a problem when trying to create user authentication from a remote MySQL database.</p>

<p>Following the steps from here: <a href="http://webpy.org/cookbook/userauthpgsql" rel="nofollow">http://webpy.org/cookbook/userauthpgsql</a></p>

<p>The exact same program works from the python commandline, but for some reason when trying to connect to the remote MySQL database from Apache, I get the following error:</p>

<pre><code>&lt;type 'exceptions.AttributeError'&gt; at /login
'module' object has no attribute 'connect'
</code></pre>

<p>Things I've tried:</p>

<ol>
<li>List item</li>
<li>Disabled SELinux</li>
<li>Added permissions for apache@myserversIP to the MySQL.</li>
<li>Tried both MySQLdb &amp; web.database for the connection</li>
<li>Googled a lot.</li>
</ol>

<p>Here's the code that is being run from my main program:</p>

<pre><code>myDB = MySQLdb.connect(host='ip',user='user',passwd='password',db='db',port=3306 );
cHandler = myDB.cursor()
cHandler.execute("SHOW TABLES;")
results = cHandler.fetchall()
for items in results:
print items
</code></pre>

<p>Any help regarding the issue, or ways to diagnose it further would be appreciated a lot! Thanks</p>

<p>Edit1: I checked where the MySQLdb is being searched from: /usr/local/lib/python2.7/site-packages<br>
Which seems to be correct.</p>

<p>Edit2:<br>
    ldd mod_wsgi.so<br>
    linux-vdso.so.1 =>  (0x00007fff4b5fd000)<br>
    libpython2.7.so.1.0 => /lib64/libpython2.7.so.1.0<br>
    libpthread.so.0 => /lib64/libpthread.so.0<br>
    libdl.so.2 => /lib64/libdl.so.2<br>
    libutil.so.1 => /lib64/libutil.so.1<br>
    libm.so.6 => /lib64/libm.so.6<br>
    libc.so.6 => /lib64/libc.so.6<br>
    /lib64/ld-linux-x86-64.so.2   </p>

<p>As has been commented, check to see if there is a file within the same directory as the file you're trying to run, that has the name MySQLdb.py</p>

python apache mod-wsgi mysql-python web.py