|
|
 |
|
Title: Using the MySQLdb interface
Submitter: Mark Nenadov
(other recipes)
Last Updated: 2002/05/12
Version no: 1.4
Category:
Databases
|
|
13 vote(s)
|
|
|
|
Description:
A simple example showing how to use the MySQLdb interface to function with your MySQL database.
Source: Text Source
import MySQLdb
Con = MySQLdb.Connect(host="127.0.0.1", port=3306, user="joe", passwd="egf42" db="tst")
Cursor = Con.cursor()
sql = "SELECT * FROM Users"
Cursor.execute(sql)
Results = Cursor.fetchall()
Con.close()
Discussion:
This is pretty self explanitory. You can get the MySQLdb module from http://sourceforge.net/projects/mysql-python
|
|
Add comment
|
|
Number of comments: 4
New Link for Downloads, Steve Holden, 2002/05/02
Note that for up-to-date distributions of MySQLdb you need to go to http://sourceforge.net/projects/mysql-python
Add comment
Thank you!, Mark Nenadov, 2002/05/12
I will update the url so nobody gets mislead.
Add comment
Typo, Patrick Paysant, 2002/11/23
In order to have the script working, I have to add a comma between passwd and db parameters.
As here :
Con = MySQLdb.Connect(host="127.0.0.1", port=3306, user="joe", passwd="egf42", db="tst")
Anyway, thanks for this recipe, it help me to start with mysql-python.
Add comment
UNIX Sockets, Reed O'Brien, 2006/04/28
con = MySQLdb.Connect(host='localhost', port=3306, user='user', passwd='secret', db='dbname', unix_socket='/var/lib/mysql/mysql.sock')
sockets are faster on localhost and some distributions of linux keep things in funny places... You can just add the unix_socket parameter like above for Fedora Core 3.
Maybe named_pipe on windows is similar; I can't say though.
Add comment
|
|
|
|
|
 |
|