Python MySQL Insert Query:
(1) You have to open the Xampp control panel and press the Apache and MySQL start button. If Apache and MySQL are highlighted in green color it means they start working. Now open your browser and type “http://localhost/phpmyadmin/“. [Follow this blog for all these steps- Create MySQL Database and Connection in Python].
|We can use the PyCharm code editor for this example. If you do not know about it then follow this link- How to install PyCharm for Python and create a program in it.|
(2) Insert query is used to insert data into the database table and this can be done by writing code in the PyCharm code editor as shown below.
Note: We always need to call the connection’s commit method to write our changes out to the database. Otherwise, when the connection is closed, our changes may be lost. In fact, until we call the commit method, none of our inserts may be visible from other database connections.
(3) Now open localhost/phpmyadmin in the browser and click on the employee database, you find the employee_table. After clicking on the employee table, you see that values insert into the database as shown below. (Follow this blog for all steps “Create Table In MySQL Python“).
(4) If we want to insert multiple rows in a database table, we insert values in the list format as shown below.
(5) Now go to localhost/phpmyadmin in the browser, and you see that values insert into the database as shown below.