Python connection MySQL

Source: Internet
Author: User

After you install Python, you also need to install PYMYSQL, installation steps:

Open https://pypi.python.org/pypi/PyMySQL#downloads, download pymysql, unzip after download:

After decompression, use CMD to enter the Pymsql directory:

Then execute the python setup.py install command:

You will see that the command window is installed automatically, waiting for the installation to succeed.

After successful installation, enter the Python IDE (Eclipse) or another editor for validation, sample code:

ImportPymysql#address port user password database name codeconn = Pymysql.connect (host="127.0.0.1", port=3306, user="Root", passwd="123456", db="afbxV1.0", charset="UTF8"); Cur= Conn.cursor ();#ConnectionCur.execute ("select * from Tb_policy_info limit");#Execute Query forCinchCur#traversing Cursors    Print(c); Cur.close (); Conn.close ();

(1, ' 1234567 ', 113, 351, None, 237,-2, Datetime.datetime (9, 8,,, 8), Datetime.datetime (2016, 9, 9, 18, 14, 8) , none, Decimal (' 10000.00 '), 1, none, Datetime.datetime (9, 8, 2016, 9, 9, Datetime.datetime), 8, +, +), None)
(3323, ' 123456 ', 94, 319, None, 355, 3, Datetime.datetime (+, 2016, 7, 18, 21, 25 , 6), none, Decimal (' 123.00 '), 104, none, 3, None, Datetime.datetime (2016, 7, up, up, up), Datetime.datetime ( 7, (+), (-), None)
(3324, ' 123456 ', Max, Max, none, 355, 3, Datetime.datetime (59, +, +, +), none, none, Decimal (' 0.00 '), 104, None, 3, None, Datetime.datetime (Datetime.datetime, 7, 7, (+), +/-), (as of), [+], (+)--
(3330, ' a ', 354, 3, Datetime.datetime (2016, 7, 19, 10, 29, 47, +, +, +) ), None, Decimal (' 12.00 '), 104, none, 3, None, Datetime.datetime (7, 9), Datetime.datetime (2016, 7, 1 9, ten, 9), None)
(3347, ' 846513 ',---------------3, Datetime.datetime (7, 0.00, one, 59, 104), none, none, 233, None, 3, None, Datetime.datetime (7, 7, one, +), Datetime.datetime (() () (() () ()-----------
(3348, ' 2345 ', 94, 319, None, 233, 3, Datetime.datetime (7, 3), Datetime.datetime (2016, 7, 19, 11, 58, 19 ), None, Decimal (' 123.00 '), 104, none, 3, None, Datetime.datetime (7, 2016, 0, 7), Datetime.datetime 1, 3), None)
(3349, ' 456423 ', 233, 3, Datetime.datetime (7, 3), Datetime.datetime (2016, 7, 19, 11, 59, 3), None, Decimal (' 12.00 '), no, 104, none, 3, None, Datetime.datetime (0, 7,), Datetime.datetime (2016, 7, 1, 3), None)
(3350, ' FGHFJHFG ', 94, 319, None, 233, 3, Datetime.datetime (7, 2016, 7, 19, 12, 0 , (), None, Decimal (' 123.00 '), 104, none, 3, None, Datetime.datetime (7, 2, 6), Datetime.datetime (2016, 7, +, 2, 6), None)
(3351, ' E001 ', 94, 319, None, 308, 3, Datetime.datetime (7, 2016, 7, 19, 12, 11, 4 2), None, Decimal (' 100.00 '), no, 104, none, 3, None, Datetime.datetime (2016, 7, 7 , +,----), None)
(3352, ' E002 ', Max, 3, Datetime.datetime (7, 2016, 7, 19, 12, 12, 2, 308, Datetime.datetime) 0), None, Decimal (' 111.00 '), no, 104, none, 3, None, Datetime.datetime (2016, 7, 7 , +,----), None)

Print data, verify success.

Python connection MySQL

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.