Home arrow Python arrow Page 2 - MySQL Connectivity With Python

Getting Started - Python

Python comes with a bunch of different modules that allow youto add new capabilities to your Python scripts. One of the more usefulones is the MySQLdb module, which allows you to execute SQL queries on aMySQL database through your Python application. This articledemonstrates basic usage of this module with simple examples andillustrations.

TABLE OF CONTENTS:
  1. MySQL Connectivity With Python
  2. Getting Started
  3. Animal Antics
  4. One By One
  5. A Different Species
  6. Be Prepared
  7. Endgame
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 179
August 21, 2002

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
In the words of its author, MySQLdb is "a thread-compatible interface to the popular MySQL database server that provides the Python database API." Developed by Andy Dustman, this module is needed for MySQL database connectivity under Python.

The first thing to do is make sure that you have the MySQLdb module installed on your Python development system. The easiest way to check this via the interactive Python command line interpreter - as the following example demonstrates:

Python 1.5.2 (#1, Feb 1 2000, 16:32:16) [GCC egcs-2.91.66 19990314/Linux (egcs- on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import MySQLdb Traceback (innermost last): File "<stdin>", line 1, in ? ImportError: No module named MySQLdb >>>
If you see something like the error message above, you can safely assume that the module is not installed on your system. Drop by http://sourceforge.net/projects/mysql-python, download the latest copy of the MySQLdb distribution, and extract and install it on your system.

$ tar -xzvf MySQL-python-0.9.2.tar.gz $ cd MySQL-python-0.9.2 $ python setup.py build $ python setup.py install
Now, you can verify that the module has been installed by trying to import it again via the command line.

Python 1.5.2 (#1, Feb 1 2000, 16:32:16) [GCC egcs-2.91.66 19990314/Linux (egcs- on linux-i386 Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam >>> import MySQLdb >>>
No problems this time round - which means we can proceed to actually writing some code.

 
 
>>> More Python Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PYTHON ARTICLES

- Python Big Data Company Gets DARPA Funding
- Python 32 Now Available
- Final Alpha for Python 3.2 is Released
- Python 3.1: String Formatting
- Python 3.1: Strings and Quotes
- Python 3.1: Programming Basics and Strings
- Tuples and Other Python Object Types
- The Dictionary Python Object Type
- String and List Python Object Types
- Introducing Python Object Types
- Mobile Programming using PyS60: Advanced UI ...
- Nested Functions in Python
- Python Parameters, Functions and Arguments
- Python Statements and Functions
- Statements and Iterators in Python

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: