Passing an insertion through MySQL for Python
As you can see, inserting data into MySQL is a straightforward process that is largely based around ensuring that the database daemon knows where you want your data placed. Inserting data into MySQL may seem a bit more complicated than retrieving it but the previous discussion shows it is still logical, but just requires a few more keywords in order to be useful.
Setting up the preliminaries
Using INSERT
with MySQL for Python is just as easy as using SELECT
. As we saw in the previous chapter, we pass the command to MySQL using the execute()
method of the database cursor object.
We will again use the fish
database and the menu
table as follows:
+----+----------------+-------+ | id | name | price | +----+----------------+-------+ | 1 | tuna | 7.50 | | 2 | bass | 6.75 | | 3 | salmon | 9.50 | | 4 | catfish | 5.00 | | 5 | trout | 6.00 | | 6 | haddock | 6.50 | | 7 | yellowfin...