hi,

i need the code to connect mysql through python programming language

Recommended Answers

All 2 Replies

Here's an example to get you started.

import MySQLdb

conn = MySQLdb.connect (host = "nephews", user = "huey", passwd = "dewey", db = "louie")
cursor = conn.cursor ()
table_name = "kumquat"

nlines = cursor.execute ("DROP TABLE IF EXISTS " + table_name)
for x in range(nlines):
	print cursor.fetchone ()
cursor.close ()

tdesc  = "CREATE TABLE " + table_name + "("
tdesc  = tdesc + "IDseq INT(7) UNSIGNED,"
tdesc  = tdesc + "Protocol VARCHAR(8), "
tdesc  = tdesc + "Function VARCHAR(8), "
tdesc  = tdesc + "Threads INT(10) UNSIGNED, "
tdesc  = tdesc + "Speed DECIMAL(10,3) "
tdesc  = tdesc + ")"
cursor = conn.cursor ()
nlines = cursor.execute (tdesc)
for x in range(nlines):
	print cursor.fetchone ()
cursor.close ()
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.