Python MySQL connection. Running on a Virtual Machine
Question: I am trying to establish a connection to MySQL that is running locally using
python. i use the following code

    
    
    import MySQLdb
    db = MySQLdb.connect("localhost","username","password","dbname")
    

I am working on a virtual machine and I am running both the Python and MySQL
on the VM. I am not able to make a connection.

I get this errror

    
    
    OperationalError: (2003, "Can't connect to MySQL server on 'localhost' (10061)")
    

I have tried providing the ip address of the VM in place of localhost and
still didn't work. I tried specifying the port number too. Is the connection
different because it runs on a VM??


Answer: When you try to connect directly to mysql Database from command line does it
work?

What OS is your VM running? If its a Unix then is there a mysqld process
runnning?

In any case this may not have anything to do with Python. Your code snipppet
looks ok. You just need to resolve the connectivity issue. Look at this page
for details on how you could get to to the root of this problem.

<http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html>

I hope that this helps.

