O'Reilly logo

MySQL for Python by Albert Lukaszewski, PhD

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 | +----+----------------+-------+ ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required