ImportError: No module named '_mysql' when trying to connect to mysql from cygwin

Dear experts,
I am a newbie to mysql and cygwin..
Here is what I did:
Installed mysql on Win 8. Installed cygwin and python 3.4.

I originally could not connect to mysql on my PC from cygwin (using cygdrive path) so, I also installed mysql client for cygwin downloading "MySQL-python-1.2.4b4.win32-py2.7" .. also installed mysql for cygwin . Below pic shows the cygwin  mysql packages I had to install further..

install-mysql-cygwin.PNG .

I was then able to connect to mysql.
I can run python programs on cygwin now, connect to mysql also, but  I am unable to connect to mysql within python. I am unable to find exact information online...Could you please help me and tell what I am i missing here? Thanks for helping me with the steps

$ which mysql
/usr/bin/mysql

$ which py
/cygdrive/c/Windows/py

$ mysql -u root -p -h 127.0.0.1
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 18
Server version: 5.6.27-log MySQL Community Server (GPL)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Below is python test script  to connect to mysql :::

$ cat my.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import _mysql
import sys

try:
    con = mdb.connect('localhost', 'testuser', 'test623', 'testdb');

    cur = con.cursor()
    cur.execute("SELECT VERSION()")

    ver = cur.fetchone()

    print("Database version:%s" % ver)

finally:

    if con:
        con.close()


Error ::

$ ./my.py
Traceback (most recent call last):
  File "./my.py", line 4, in <module>
    import _mysql
ImportError: No module named '_mysql'

Another try using MySQLdb  :

$ cat my2.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import MySQLdb as mdb
import sys

try:
    con = mdb.connect('localhost', 'testuser', 'test623', 'testdb');

    cur = con.cursor()
    cur.execute("SELECT VERSION()")

    ver = cur.fetchone()

    print("Database version:%s" % ver)

finally:

    if con:
        con.close()

$ ./my2.py
Traceback (most recent call last):
  File "./my2.py", line 4, in <module>
    import MySQLdb as mdb
ImportError: No module named 'MySQLdb'
newbieexpertAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kulboyCommented:
you should check on what port mysql is listening:

To find a listener on a port, do this:
netstat -tln

Open in new window


You should see a line that looks like this if mysql is indeed listening on that port.

tcp        0      0 127.0.0.1:3306              0.0.0.0:*                   LISTEN      

Open in new window


then use that ip to check if it works on that port
gheistCommented:
Where is Linux?
kulboyCommented:
Are you trying to connect to the cygwin install on mysql or the windows version?
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

theGhost_k8Database ConsultantCommented:
gheistCommented:
You forget cygwin, install activestate python and install any module you want from pypi with pip gui (no need for older setuptools)
Walter RitzelSenior Software EngineerCommented:
Your problem seems to be that you dont have any module in python to connect to mysql.
I'm not familiar with this environment using cygwin, but I would say that you need to do something like use pip to install one of the mysql modules on your python:
Trys this on your prompt: pip install mysqlconnector-python
If it works, your example my2.py should now works without issue..

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Python

From novice to tech pro — start learning today.