Python connects to MySQL database under Windows

Source: Internet
Author: User

One, install Mysql-python

Python connects MySQL database requires Python interface to MySQL package, package name is

Mysql-python

, the PyPI is now in the 1.2.5 version. Mysql-python is installed under Windows through the installer of the. exe file.

If you have already installed Python that needs to be written to the registry, refer to this article:registration (Registry) issues after Windows installation python2.7.

And then start installing Mysql-python, but here's a pit, from the Mysql-python version of PyPI-

Mysql-python-1.2.5.win32-py2.7.exe (MD5)--not necessarily available, because the Python environment and Mysql-python may not match the number of software bits,

For example, my locally installed Python is 64 bits, and the Mysql-python downloaded from PyPI cannot be used.

will report such an error: python importerror:dll load failed:%1

Just install the correct number of Mysql-python on it, here to share the next 64 bits:

Mysql-python-1.2.5.win-amd64-py2.7.exe

Second, simple to use

The reference code is as follows:

1Python 2.7.6 (default, Nov, 19:24:24) [MSC v.1500 64bit (AMD64)] on Win322 ImportMySQLdb3conn = MySQLdb.connect (host='localhost', port=3306,user='Root', passwd='123456', db='Test')4Cur =conn.cursor ()5Cur.execute ('Select ' title ', ' text ' from ' entries ' limit')62L7 Cur.fetchall ()8(('Bokeyuan','Bokeyuan Text ...'), ('Google Translate','Google Translate text ...'))9 cur.close ()TenConn.close ()

Python connects to MySQL database under Windows

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.