Python Tutorials · Python MySQL
MySQL Insert
Learn all about MySQL Insert in this comprehensive tutorial.
5 min read advanced
- •To fill a table in MySQL, use the "INSERT INTO" statement.
- •To insert multiple rows into a table, use the executemany() method.
- •You can get the id of the row you just inserted by asking the cursor object.
Insert Into Table
To fill a table in MySQL, use the "INSERT INTO" statement.
python
Note: Important!: Notice the statement:
mydb.commit(). It is required to make the
changes, otherwise no
changes are made to the table.
Insert Multiple Rows
To insert multiple rows into a table, use the executemany() method.
The second parameter of the executemany() method is a list of tuples, containing the data you want to insert:
python
Get Inserted ID
You can get the id of the row you just inserted by asking the cursor object.
Note: Note: If you insert more than one row, the id of the last
inserted row is returned.
python
Module quiz
Test your knowledge on this module
5 questions