Python MySQL Create Insert

Insert Table

Steps for Insert MySQL tables in Python

  • To insert a table in MySQL, use the "INSERT INTO" statement.
  • Make sure you have defined the name of the table while you insert the connection.

Syntax:

  							   
 INSERT INTO student (id, name) VALUES (01, "John")
 INSERT INTO employee (id, name, salary) VALUES(01, "John", 10000)
 

Example:

Inserting a record into two the "customers" and "employee" table:



Output:

  2 Record Inserted   

Insert Multiple Rows

Example:

The executemany() method is used to insert multiple rows into a table:

The second parameter of the executemany() method is a list of tuples, containing the data you want to insert:



Output:

 record successfully inserted.