6 Replies - 1377 Views - Last Post: 24 September 2011 - 06:32 AM Rate Topic: -----

#1 cupidvogel   User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

How can Python access my database?

Posted 23 September 2011 - 11:11 PM

Hi, I have installed MySQL server 5.1 in my C drive and populated it with tables and data. Then I installed Python in C drive and further installed MySQLdb on it. Now from within Python I import MySQLdb and work with MySQL alright, but can anyone tell me how does Python get access to the database? Is it because both MySQL and Python are located in the same drive (C), or it is because that they are located in the same computer (localhost), Python can access it no matter where MySQL be located (D or E drives)?

Is This A Good Question/Topic? 0
  • +

Replies To: How can Python access my database?

#2 Martyr2   User is offline

  • Programming Theoretician
  • member icon

Reputation: 5259
  • View blog
  • Posts: 14,073
  • Joined: 18-April 07

Re: How can Python access my database?

Posted 23 September 2011 - 11:35 PM

Python (and many other languages) can access databases anywhere... same drive, different drives, network drives, over the Internet etc. Your programming language uses a database driver software to learn how to talk to the given database and then you supply the IP/drive/networkname and port, username and password when you go to connect.

db = mysql.connect("localhost","joebob","moonpie","thangs")



Here you are telling it the database is localhost. It could have been an IP/Port combination. As long as you can get to it through a network, python (or a given language with database support) can then theoretically access it.

:)
Was This Post Helpful? 1
  • +
  • -

#3 cupidvogel   User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: How can Python access my database?

Posted 23 September 2011 - 11:39 PM

Cool. But Python has this Pythonpath thing wich tells it to look for the desired item in the list of specified directories, right? So suppose my MySQL server is located in the E drive, and that path is not included in the Pythonpath, how can Python access it?
Was This Post Helpful? 0
  • +
  • -

#4 Motoma   User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 798
  • Joined: 08-June 10

Re: How can Python access my database?

Posted 24 September 2011 - 06:23 AM

I think you're misunderstanding; MySQL is a server awaiting connections from various computers on the internet via TCP/IP. You just happen to be connecting to it from the same machine, but this is not necessary.
Was This Post Helpful? 1
  • +
  • -

#5 cupidvogel   User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: How can Python access my database?

Posted 24 September 2011 - 06:25 AM

I see. So you mean to say that MySQL's location doesn't matter, whatever drive be it located in, the computer (same or another one) will find and connect to it eventually?
Was This Post Helpful? 0
  • +
  • -

#6 Motoma   User is offline

  • D.I.C Addict
  • member icon

Reputation: 452
  • View blog
  • Posts: 798
  • Joined: 08-June 10

Re: How can Python access my database?

Posted 24 September 2011 - 06:31 AM

You will be able to connect to it as long as you know it's hostname or IP and you have a route between your computer and the computer MySQL is hosted on.
Was This Post Helpful? 1
  • +
  • -

#7 cupidvogel   User is offline

  • D.I.C Addict

Reputation: 31
  • View blog
  • Posts: 593
  • Joined: 25-November 10

Re: How can Python access my database?

Posted 24 September 2011 - 06:32 AM

Cool. Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1