[Tutor] Python to connect to MySql
tpc at csua.berkeley.edu
tpc at csua.berkeley.edu
Thu Jul 1 12:08:28 EDT 2004
hi Bernard, you might want to look at MySQLdb for win32:
http://sourceforge.net/projects/mysql-python
Once installed, a simple thing would be to import MySQLdb, and run the
following code to test:
def mySQLtest():
DB = 'mysql'
HOST = 'localhost'
DB_USER = 'root'
DB_PASSWORD = ''
conn = MySQLdb.Connection(db=DB, host=DB_HOST, user=DB_USER,
passwd=DB_PASSWORD)
cursor = conn.cursor()
sql = """show tables;"""
cursor.execute(sql)
results = cursor.fetchall()
cursor.close()
conn.close()
return results
I hope that helps you.
On Thu, 1 Jul 2004, Bernard Lebel wrote:
> Hello,
>
> I'm wondering if there is any way to connect to a MySql server (and retreive
> information) without the need of an ActiveX object. Right this is what I'm
> doing, but again I want to get rid of the active objects.
>
> I have found few things on the internet, but some are for Unix servers and
> require a C compiler and things like that. Nothing as simple and
> straigthforward as an active object.
>
> Any suggestion?
> I'm using MySql 4.0.16
>
>
> Thanks
> Bernard
>
>
>
> # Current code:
> import win32com.client
>
> # Create database ActiveX object
> oDB = win32com.client.Dispatch( "ADODB.Connection" )
>
> # Send connection instructions to database
> oDB.ConnectionString = 'driver={MySQL}; server=xxx.xxx.x.x; uid=userid;
> pwd=password; database=database'
>
> oDB.open
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
More information about the Tutor
mailing list