Python link MySQL

Source: Internet
Author: User

1. Installing MYSQLDB

MYSQLDB is the interface for the Python link MySQL database, which implements the Python database API specification V2.0, built on the MySQL C API.

http://sourceforge.net/projects/mysql-python/files/mysql-python/

I downloaded the 1.2.3 version

2. Code

1 #!/usr/bin/python2 #-*-coding:utf-8-*-3 ImportMySQLdb4 #Open a database connection5db = MySQLdb.connect (host='127.0.0.1', port=3306, user='Root', passwd="', db='XXX', charset='UTF8')6 #get an operation cursor using the cursor () method7cursor =db.cursor ()8 #executing SQL statements using the Execute method9Cursor.execute ("SELECT VERSION ()")Tendata =Cursor.fetchone () One Print "MySQL Version%s"%Data A #To close a database connection -Db.close ()

This is the most basic of a small example

Python link MySQL

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.