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
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 |
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 |
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