Python MySQLLesson 115Free preview
MySQL Insert
This lesson is part of Python · All levels
Summary
This lesson discusses how to add data to a MySQL table using the INSERT INTO command from Python. You'll use the placeholder %s for the query parameter to secure the value from the SQL injection, and then call conn.commit() to save it. For many data at once, the cursor.executemany(method is available.
Key points
- Basic format: INSERT INTO name_table (column) VALUES (value)
- MySQL-connector uses a placeholder %s filled from a separate argument tuple.
- Separating values from the query string prevents SQL injection and makes the quotation secure.
- Cursor.executemany() insert many lines into one call.
- New data changes are stored after conn.commit() is called.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.