How to Use Python with MySQL: Install, Configure, and Perform CRUD on Windows
This guide walks you through installing MySQL on Windows, setting up the Python pymysql driver, using MySQL Workbench for visual database management, and writing basic Python code to create, read, update, and delete records in a MySQL database.
Introduction
This article shows how to use Python to operate a MySQL database on a Windows machine, covering installation, configuration, and basic CRUD operations.
Install MySQL (Windows)
Download mysql-5.6.33-winx64, add the bin directory to the system Path, edit my-default.ini to set basedir and datadir, then run mysqld -install and net start mysql to start the service.
Install pymysql
Open a command prompt with administrator rights and execute pip install PyMySql to install the Python MySQL driver.
Use MySQL Workbench
Download MySQL Workbench, create a new schema, and add tables via the GUI by selecting the database, right‑clicking Tables, and defining fields and data types.
Basic CRUD with Python
Example code for connecting and operating on the database:
conn = pymysql.connect(host='localhost', user='root', passwd='', db='first')
cur = conn.cursor()
# perform SQL operations with cur.execute(...)
cur.close()
conn.close()The connection object acts as a pipeline, while the cursor is the carrier for executing SQL statements. CRUD functions simply call cur.execute() with appropriate SQL.
Conclusion
The article sets up a local MySQL database on Windows; similar steps apply to Linux or remote servers. After installation, mastering SQL and Python coding is essential for effective backend development.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
