MariaDB is an open source Database Management System and its predecessor to MySQL. The pymysql client can be used to interact with MariaDB similar to that of MySQL using Python.
In this article we will look into the process of inserting rows to a table of the database using pymysql. You can insert one row or multiple rows at once. The connector code is required to connect the commands to the particular database. To insert data use the following syntax:
Syntax: INSERT INTO table_name column1, column2 VALUES (value1, value2)
Note: The INSERT query is used to insert one or multiple rows in a table.
To insert one row in table PRODUCT.
To insert multiple values at once, executemany() method is used. This method iterates through the sequence of parameters, passing the current parameter to the execute method.
To insert multiple row in table PRODUCT.
- The cursor() is used in order to iterate through the rows.
- Without the command conn.commit() the changes will not be saved.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Python MariaDB - Drop Table using PyMySQL
- Create Database in MariaDB using PyMySQL in Python
- Python MariaDB - Select Query using PyMySQL
- Python MariaDB - Order By Clause using PyMySQL
- Python MariaDB - Update Query using PyMySQL
- Python MariaDB - Delete Query using PyMySQL
- Python MariaDB - Limit Clause using PyMySQL
- Python MariaDB - Where Clause using PyMySQL
- PostgreSQL - Insert Data Into a Table using Python
- Connect to MySQL using PyMySQL in Python
- Python MySQL - Insert into Table
- Python MySQL - Insert record if not exists in table
- Display the Pandas DataFrame in table style and border around the table and not around the rows
- Python program to insert an element into sorted list
- Read SQL database table into a Pandas DataFrame using SQLAlchemy
- Python | Convert an HTML table into excel
- Convert HTML table into CSV file in python
- Char_Length()Function AND ASCII() Function in MariaDB
- Python program to convert Set into Tuple and Tuple into Set
- Inserting variables to database table using Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.