mysqldb:http://sourceforge.net/projects/mysql-python/
After the download is uncompressed and placed in the%python_home%/lib/site-packages directory, Python will automatically find the package.
MySQLdb is basically the Python version of the MySQL C API, followed by the Python Database API Specification v2.0.
Other:
1. Platform and version
Linux kernel 2.6,GCC 3.4.4,GLIBC 2.4
Python 2.4.3
MySQL 5.0.19
Mysql-python 1.2.1-P2
2. Installing Mysql-python
Tar Xvfz mysql-python-1.2.1_p2.tar.gz
CD MYSQL-PYTHON-1.2.1_P2
Python setup.py Build
Python setup.py Install
3. Use
Import MySQLdb
3.1. Connect
conn = mysqldb.connection (host, user, password, dbname)
3.2. Select a database
conn.select_db (' database name ')
3.3. Get cursor
cur = conn.cursor ()
3.4. Cursor Position setting
Cur.scroll (int, mode)
Mode can be a relative position or an absolute position, respectively relative and absolute.
3.5. Select
Cur.execute (' select clause ')
For example
Cur.execute (' select * FROM MyTable ')
row = Cur.fetchall ()
Or:
Row1 = Cur.fetchone ()
3.6. Insert
Cur.execute (' inset clause ')
For example
Cur.execute (' INSERT into table (Row1, Row2) VALUES (/' 111/',/' 222/') ')
Conn.commit ()
3.7. Update
Cur.execute (' update clause ')
For example
Cur.execute ("Update table Set row1 = ' where row2 = ' row2 '")
Conn.commit ()
3.8. Delete
Cur.execute (' delete clause ')
For example
Cur.execute ("Delete from table where Row1 = ' row1 '")
Conn.commit ()
Http://www.python123.cn/PythonInternet/20090609_11.html
Python instance code to connect to MySQL