Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

MySQL Databases and Python (Summary)

In this video course, you saw how to use MySQL Connector/Python to integrate a MySQL database with your Python application. You also saw some unique features of a MySQL database that differentiate it from other SQL databases.

Along the way, you learned some programming best practices that are worth considering when it comes to establishing a connection, creating tables, and inserting and updating records in a database application. You also developed a sample MySQL database for an online movie rating system and interacted with it directly from your Python application.

In this video course, you learned how to:

  • Connect your Python app with a MySQL database
  • Bring data from a MySQL database into Python for further analysis
  • Execute SQL queries from your Python application
  • Handle exceptions while accessing the database
  • Prevent SQL injection attacks on your application
Download

Course Slides (.pdf)

5.9 MB

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

00:00 In this summary lesson, I will wrap up everything I have covered in this course, highlighting important concepts and providing recommendations for further advancement of your knowledge.

00:12 In this course, you have learned how to set up local databases. You start with the installation of the local MySQL server suitable for your operating system, followed by setting up the Python MySQL connector that authenticates a user and enables interactions with the MySQL system.

00:34 Next, you establish the connection to the desired database by adding the database parameter to the parameter list of MySQLConnect.connect() function, and specifying its value.

00:47 It is also helpful to set up tools like MySQL Workbench. It has a user-friendly interface to perform administrative tasks such as root and other user account management to check on the server status, to perform data import and export operations, and to write and execute SQL queries.

01:10 You have learned how to create a simple relational data model in Python using linked MySQL tables. As a rule of thumb, you first create parent tables using the CREATE TABLE SQL command, defining ID columns as primary keys.

01:28 Then you create a child table specifying foreign keys in an SQL query and referencing the corresponding columns in the parent tables.

01:39 You have also learned how to import data from CSV files to MySQL tables via pathlib and CSV Python libraries. You have learned how to effectively manipulate and query data using MySQL relational data structures within Python applications.

02:01 Specifically, you know how to retrieve records from the MySQL database using simple SQL queries, containing SELECT commands with an asterisk symbol, and Python methods for fetching data such as .fetchall() and .fetchmany().

02:19 You have seen how a relational data model allows extraction of deeper insights from data like top five money-making movies, for example. You have learned how to write more complex SQL queries that involve table join operations.

02:38 MySQL DBMS is not the one and only way for data storage and retrieval.

02:46 With a powerful SQL toolkit like SQLAlchemy, you do not need a database server to enable database functionality of your code. For further exploration of database topics in Python, I strongly recommend learning SQLAlchemy.

03:04 If you are a beginner, SQLAlchemy Unified tutorial is the place to start, as it has a complex architecture with so-called core and object-relational mapping or ORM APIs.

03:22 SQLAlchemy and Python SQLite allow you to store data in SQL databases and flat files that are often human-readable text files. You can further investigate these topics in SQLite and SQLAlchemy in Python: Move your Data Beyond Flat Files course, that is available in both tutorial and video course formats.

03:49 You can also manage and retrieve data from a MySQL database using FastAPI. FastAPI is a modern framework for building web APIs that easily integrate with MySQL, and I strongly recommend that you learn the main concepts of FastAPI and best practices creating web APIs from the Real Python tutorial and video course on Python REST API with FastAPI.

04:19 Having mastered MySQL, SQLAlchemy, and FastAPI, you’ll be fully equipped with powerful tools to develop high performance web applications that effectively share the same data among different users on different computers.

04:39 Never stop growing your mastery.

04:43 Congratulations! You have completed MySQL Databases and Python course.

Avatar image for Phil M

Phil M on Oct. 13, 2025

I took me several months to complete, but I learned about installing MySQL and MySQL WorkBench. This required a bit of extra studying and even some assistance from AI, which was another experience. I was able to learn and figure out how to script all the lessons as python scripts which achived matching results as the lesson’s videos. This expanded my Python and SQL knowledge in several different areas. I needed to reach out to these other resources to get the answers to move forward. I love Real Python but working through another tutorial to try and get an answer for just one question on how to make things work as I was trying to learn it – just was not the answer. There were several times I tried this approach with Real Python and each time I became more and more bogged down with additional learning that did not ever answer my question. Now I was left with a completing tutorial, or a partically completed or bookmarked tutorial and still no answers. Just as one tutorial in Real Python does not necessarily give me the answers to a problem in another tutorial, so it is also true that my mind has a hard time figuring out what it does not know. This describes the vortex of the downward spin to learning nothing. That is why slow learners like myself need to have multiple tools available to address these types of programming problems. If it wasn’t for computers and word processors (todays editors with linters) I would not even be try to program or even adding my comments to the decession. All-in-all, I am very grateful for the journey and very appreciative of all the hard work that I had to put in to complete this tutorial (MySQL Databases and Python) and thank you, too, Nataliya Portman for all your hard work! -Phil

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Oct. 13, 2025

@Phil M Thanks so much for sharing your journey, and congratulations on pushing through such a challenging course!

It sounds like you learned a ton, even if the path was sometimes bumpy. When you get stuck in the future, you might find it helpful to stop by our Real Python Slack community or join the next Office Hours session. Both are great places to get quick help and connect with other learners working through similar topics.

Thanks again for the thoughtful feedback and for the shout-out to Nataliya! We really appreciate it 😊

Become a Member to join the conversation.