How does python use the pymysql module and the pythonpymysql module?

Source: Internet
Author: User

How does python use the pymysql module and the pythonpymysql module?
Python 3.x detailed description of the pymysql module for MySQL operations

Preface pymysql is a module used to operate MySQL in Python. Its usage is almost the same as that of MySQLdb. However, pymysql currently supports python3.x, while MySQLdb does not support version 3.x.

I. Installation

pip3 install pymysql

Ii. pymysql Method

  • Pymysql. connect () parameter description

Parameters Type Description
Host Str Mysql server address
Port Int Mysql server port number
User Str User Name
Passwd Str Password
Db Str Database Name
Charset Str Connection code
  • Methods supported by the connection object

Method Description
Cursor () Use this connection to create and return a cursor
Commit () Submit current transaction
Rollback () Roll back the current transaction
Close () Close connection object
  • Method supported by cursor object

Method Description
Execute (op) Execute the SQL statement of a Database
Fetchone () Obtain the next row of the result set
Fetchmany (size) Obtain the following rows of the result set.
Fetchall () Obtain the remaining rows in the result set.
Rowcount () Number of returned data items or affected items
Close () Close a cursor object

Iii. Operation

1. Create a transaction table to test pymysql performance:

2. Use a python script to add, delete, modify, query, and process transactions

3. Execution result

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.