{"id":3229,"date":"2014-10-19T22:32:37","date_gmt":"2014-10-20T06:32:37","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=3229"},"modified":"2024-01-06T06:51:09","modified_gmt":"2024-01-06T13:51:09","slug":"python-mysql","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/python-mysql\/","title":{"rendered":"Python MySQL"},"content":{"rendered":"\n<p>This tutorial series shows you how to use MySQL Connector\/Python to access MySQL databases from Python programs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What you&#8217;ll learn:<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Connect to MySQL server from a Python program<\/li>\n\n\n\n<li>Insert, Select, Update, and Delete data in the database in Python.<\/li>\n\n\n\n<li>Call MySQL stored procedures from Python<\/li>\n\n\n\n<li>Writing \/ Reading BLOB data in MySQL database from Python.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Prerequisites<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Python Programming<\/li>\n\n\n\n<li>Basic MySQL<\/li>\n\n\n\n<li>MySQL stored procedures<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter is-resized\"><img loading=\"lazy\" decoding=\"async\" width=\"549\" height=\"289\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/Python-MySQL-1.png\" alt=\"Python MySQL\" class=\"wp-image-8974\" style=\"width:549px;height:auto\" srcset=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/Python-MySQL-1.png 549w, https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2019\/09\/Python-MySQL-1-200x105.png 200w\" sizes=\"auto, (max-width: 549px) 100vw, 549px\" \/><\/figure>\n<\/div>\n\n\n<p class=\"note\">Please note that all tutorials in this section are based on Python 3. If you&#8217;re looking to learn Python programming or refresh your Python knowledge quickly, you can check out the <a href=\"https:\/\/www.pythontutorial.net\/\" target=\"_blank\" rel=\"noreferrer noopener\">Python tutorial<\/a>.<\/p>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">Section 1. Getting Started with MySQL Connector\/Python <\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a title=\"Getting Started with MySQL Python Connector\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/getting-started-mysql-python-connector\/\">Getting Started with MySQL Python Connector<\/a> &#8211; Help you get started with MySQL Connector\/Python by introducing the features of the MySQL Python connector and guiding you through the installation process on your system.<\/li>\n\n\n\n<li><a title=\"Python MySQL - Connect to a MySQL Database in Python\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-connecting-mysql-databases\/\">Connecting to a MySQL Database in Python<\/a> &#8211; Show you how to use the connect() function and MySQLConnection object to establish a connection to a MySQL database.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">Section 2. Performing Basic Operations (CRUD)<\/h2>\n\n\n\n<p>This section shows you how to perform basic operations, including querying data, inserting data, updating data, and deleting data.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a title=\"Python MySQL - Query Data from a Table in Python\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-query\/\">Querying Data from a Table in Python<\/a> &#8211; Show you how to query data in a MySQL database in Python using Python\/Connector API, including functions like <code>fetchone<\/code>, <code>fetchmany<\/code>, and <code>fetchall<\/code>.<\/li>\n\n\n\n<li><a title=\"Python MySQL - Insert Data Into a Table\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql-insert\/\">Inserting Data Into a Table<\/a> &#8211; Learn how to insert data into a table using MySQL Connector\/Python API.<\/li>\n\n\n\n<li><a title=\"Python MySQL - Update Data in a Table\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql-update\/\">Updating Data in a Table<\/a> &#8211; Walk you through the steps required to update data in database tables using MySQL Connector\/Python API.<\/li>\n\n\n\n<li><a title=\"Python MySQL - Delete Data from a Table\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-delete-data\/\">Deleting Data from a Table<\/a>&nbsp; &#8211; Guide you on how to delete data in MySQL database using Python.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">Section 3. Stored Procedures<\/h2>\n\n\n\n<p>This section shows how to effectively work with MySQL store procedures in Python<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a title=\"Python MySQL - Call Stored Procedures in Python\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/calling-mysql-stored-procedures-python\/\">Calling Stored Procedures in Python<\/a> &#8211; Show you how to call MySQL stored procedures in Python using MySQL Connector\/Python API.<\/li>\n<\/ul>\n<\/div><\/div>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-constrained wp-block-group-is-layout-constrained\">\n<h2 class=\"wp-block-heading\">Section 4. Working with BLOB<\/h2>\n\n\n\n<p>This section covers working with BLOB data, enabling you to store large binary objects in the MySQL database. You&#8217;ll learn how to save BLOB data into the database, retrieve it, and save the data as a file.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a title=\"Python MySQL - Read &amp; Update BLOB in MySQL Database\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/\">Retrieving &amp; Updating BLOB in MySQL Database<\/a> &#8211; Show you how to work with MySQL BLOB data in Python, providing examples of updating and reading BLOB data.<\/li>\n<\/ul>\n<\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>This page shows you how to use MySQL Connector \/ Python to interact with MySQL databases from Python programs.<\/p>\n","protected":false},"author":2,"featured_media":10057,"parent":0,"menu_order":26,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-3229","page","type-page","status-publish","has-post-thumbnail","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python MySQL<\/title>\n<meta name=\"description\" content=\"This page shows you how to use MySQL Connector \/ Python to interact with MySQL databases from Python programs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python MySQL\" \/>\n<meta property=\"og:description\" content=\"This page shows you how to use MySQL Connector \/ Python to interact with MySQL databases from Python programs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/python-mysql\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-06T13:51:09+00:00\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/\",\"name\":\"Python MySQL\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/mysql-python.svg\",\"datePublished\":\"2014-10-20T06:32:37+00:00\",\"dateModified\":\"2024-01-06T13:51:09+00:00\",\"description\":\"This page shows you how to use MySQL Connector \\\/ Python to interact with MySQL databases from Python programs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/mysql-python.svg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2021\\\/04\\\/mysql-python.svg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python MySQL\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\",\"name\":\"MySQL Tutorial\",\"description\":\"A comprehensive MySQL Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mysqltutorial.org\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python MySQL","description":"This page shows you how to use MySQL Connector \/ Python to interact with MySQL databases from Python programs.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mysqltutorial.org\/python-mysql\/","og_locale":"en_US","og_type":"article","og_title":"Python MySQL","og_description":"This page shows you how to use MySQL Connector \/ Python to interact with MySQL databases from Python programs.","og_url":"https:\/\/www.mysqltutorial.org\/python-mysql\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-06T13:51:09+00:00","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/","url":"https:\/\/www.mysqltutorial.org\/python-mysql\/","name":"Python MySQL","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2021\/04\/mysql-python.svg","datePublished":"2014-10-20T06:32:37+00:00","dateModified":"2024-01-06T13:51:09+00:00","description":"This page shows you how to use MySQL Connector \/ Python to interact with MySQL databases from Python programs.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/python-mysql\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2021\/04\/mysql-python.svg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2021\/04\/mysql-python.svg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"Python MySQL"}]},{"@type":"WebSite","@id":"https:\/\/www.mysqltutorial.org\/#website","url":"https:\/\/www.mysqltutorial.org\/","name":"MySQL Tutorial","description":"A comprehensive MySQL Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mysqltutorial.org\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3229","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/comments?post=3229"}],"version-history":[{"count":5,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3229\/revisions"}],"predecessor-version":[{"id":14337,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3229\/revisions\/14337"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media\/10057"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=3229"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}