Installing the MySQLdb module for Windows python2.7

Source: Internet
Author: User

Download the corresponding version according to the number of Python bits:

32-bit: https://pypi.python.org/pypi/MySQL-python/1.2.5

64-bit: Http://arquivos.victorjabur.com/python/modules/MySQL-python-1.2.3.win-amd64-py2.7.exe

Download the corresponding version and install it directly.

Enter the code test:

  1. Import MySQLdb
  2. #-----------MySQL test code-------------
  3. Def mysql_test ():
  4. Try:
  5. Sql=' select * from student '
  6. Conn=mysqldb.connect (host=' 127.0.0.1 ', user=' root ', passwd=' test ', db=' test ', port=3306)
  7. Cur=conn.cursor ()
  8. Cur.execute (SQL)
  9. print ' conn:%s '%conn
  10. print ' cur:%s '%cur
  11. Cur.close ()
  12. Conn.close ()
  13. except Mysqldb.error,e:
  14. print ' MySQL Error%d:%s '% (e.args[0],e.args[1])
  15. If __name__=="__main__":
  16. Mysql_test ()
The test results show that the connection was successful:
    1. Conn:<_mysql.connection open to ' 127.0.0.1 ' at 2d01b28>
    2. Cur: <mysqldb.cursors.cursor object at 0x00000000031f9ef0>
If you see the following error, you should change localhost to 127.0.0.1.
    1. MySQL error 2013:lost connection to MySQL server @ ' waiting for initial communication packet ', system error: 0

Installing the MySQLdb module for Windows python2.7

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.