| | |
Code to connect mysql through python
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
Here's an example to get you started.
Python Syntax (Toggle Plain Text)
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 ()
![]() |
Similar Threads
- how do I connect to MySQL server which is firewall protected? (Python)
- Python-mysql for checking table exist or not (Python)
- mysql error only on web page (MySQL)
- python mysql doesnt work?plz help (Python)
- port forwarding in Python (Python)
- Moving to Python From PHP: Using a variable in a function (Python)
Other Threads in the Python Forum
- Previous Thread: noob stuck with something, plz help?
- Next Thread: Advanced Sorting
| Thread Tools | Search this Thread |
abrupt ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog data decimals dictionaries dictionary drive dynamic error examples excel exe file float format function gnu graphics gui heads homework http ideas import input java launcher leftmouse line linux list lists logging loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyqt python random recursion schedule script scrolledtext sqlite statistics stdout string strings sudokusolver sum table terminal text thread threading time tkinter tlapse tricks tuple tutorial twoup ubuntu unicode update urllib urllib2 variable wikipedia windows write wxpython xlib






