{"id":3297,"date":"2014-10-22T18:55:39","date_gmt":"2014-10-23T02:55:39","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=3297"},"modified":"2024-01-02T21:28:48","modified_gmt":"2024-01-03T04:28:48","slug":"python-mysql-update-data","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/","title":{"rendered":"Python MySQL &#8211; Update Data in a Table"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: In this tutorial, you will learn how to update data in a table using MySQL Connector\/Python API.<\/p>\n\n\n\n<p class=\"note\">This tutorial picks up where the <a href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-query\/\"><\/a><a href=\"https:\/\/www.mysqltutorial.org\/python-mysql-insert\/\">Inserting Data Into a Table<\/a>&nbsp;tutorial left off.<\/p>\n\n\n\n<p>To update data in a table in Python, you follow these steps:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>First, <a title=\"Python Connecting to MySQL Databases\" href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-connecting-mysql-databases\/\">connect to the MySQL server<\/a> by creating a new <code>MySQLConnection<\/code> object.<\/li>\n\n\n\n<li>Next, create a new <code>MySQLCursor<\/code> object from the <code>MySQLConnection<\/code> object.<\/li>\n\n\n\n<li>Then, call the <code>execute()<\/code> method of the <code>MySQLCursor<\/code> object. <\/li>\n\n\n\n<li>After that, call the <code>commit()<\/code> method of the <code>MySQLConnection<\/code> object after calling the <code>execute()<\/code> method to apply the changes to the database.<\/li>\n\n\n\n<li>Finally, close the cursor and database connection.<\/li>\n<\/ul>\n\n\n\n<p>The following program defines a function called <code>update_book()<\/code> to update the <code>title<\/code> of a book by <code>book_id<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">from<\/span> mysql.connector <span class=\"hljs-keyword\">import<\/span> MySQLConnection, Error\n<span class=\"hljs-keyword\">from<\/span> config <span class=\"hljs-keyword\">import<\/span> read_config\n\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">update_book<\/span><span class=\"hljs-params\">(book_id, title)<\/span>:<\/span>\n    <span class=\"hljs-comment\"># read database configuration<\/span>\n    config = read_config()\n\n    <span class=\"hljs-comment\"># prepare query and data<\/span>\n    query = <span class=\"hljs-string\">\"\"\" UPDATE books\n                SET title = %s\n                WHERE id = %s \"\"\"<\/span>\n\n    data = (title, book_id)\n\n    affected_rows = <span class=\"hljs-number\">0<\/span>  <span class=\"hljs-comment\"># Initialize the variable to store the number of affected rows<\/span>\n\n    <span class=\"hljs-keyword\">try<\/span>:\n        <span class=\"hljs-comment\"># connect to the database<\/span>\n        <span class=\"hljs-keyword\">with<\/span> MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\n            <span class=\"hljs-comment\"># update book title<\/span>\n            <span class=\"hljs-keyword\">with<\/span> conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\n                cursor.execute(query, data)\n\n                <span class=\"hljs-comment\"># get the number of affected rows<\/span>\n                affected_rows = cursor.rowcount\n\n            <span class=\"hljs-comment\"># accept the changes<\/span>\n            conn.commit()\n\n    <span class=\"hljs-keyword\">except<\/span> Error <span class=\"hljs-keyword\">as<\/span> error:\n        print(error)\n\n    <span class=\"hljs-keyword\">return<\/span> affected_rows  <span class=\"hljs-comment\"># Return the number of affected rows<\/span>\n\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\n    affected_rows = update_book(<span class=\"hljs-number\">37<\/span>, <span class=\"hljs-string\">'The Giant on the Hill *** TEST ***'<\/span>)\n    print(<span class=\"hljs-string\">f'Number of affected rows: <span class=\"hljs-subst\">{affected_rows}<\/span>'<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">Python<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">python<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>How it works.<\/p>\n\n\n\n<p>First, import the necessary modules including <code>MySQLConnection<\/code> and <code>Error<\/code> are classes from the <code>mysql.connector<\/code> module, and <code>read_config<\/code> is a function from a custom module <code>config<\/code>.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">from<\/span> mysql.connector <span class=\"hljs-keyword\">import<\/span> MySQLConnection, <span class=\"hljs-built_in\">Error<\/span>\n<span class=\"hljs-keyword\">from<\/span> config <span class=\"hljs-keyword\">import<\/span> read_config<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Second, define a  function named <code>update_book<\/code> that takes two parameters: <code>book_id<\/code> and <code>title<\/code>. The function reads the database configuration and prepares an SQL query to update the title of a book with the specified ID:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">def update_book(book_id, title):\n    <span class=\"hljs-comment\"># read database configuration<\/span>\n    config = read_config()\n\n    <span class=\"hljs-comment\"># prepare query and data<\/span>\n    query = <span class=\"hljs-string\">\"\"<\/span><span class=\"hljs-string\">\" UPDATE books\n                SET title = %s\n                WHERE id = %s \"<\/span><span class=\"hljs-string\">\"\"<\/span>\n\n    data = (title, book_id)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, open a database connection (<code>MySQLConnection<\/code>) with the configuration from the configuration file and create a cursor (<code>cursor<\/code>). Inside the nested <code>with<\/code> statement, update the book title, and return the number of affected rows obtained from <code>cursor.rowcount<\/code>:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">    affected_rows = <span class=\"hljs-number\">0<\/span>  <span class=\"hljs-comment\"># Initialize the variable to store the number of affected rows<\/span>\n\n    <span class=\"hljs-keyword\">try<\/span>:\n        <span class=\"hljs-comment\"># connect to the database<\/span>\n        with MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\n            <span class=\"hljs-comment\"># update book title<\/span>\n            with conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\n                cursor.execute(query, data)\n\n                <span class=\"hljs-comment\"># get the number of affected rows<\/span>\n                affected_rows = cursor.rowcount\n\n            <span class=\"hljs-comment\"># accept the changes<\/span>\n            conn.commit()\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fourth, display the error if it occurs during the update:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">    except <span class=\"hljs-built_in\">Error<\/span> <span class=\"hljs-keyword\">as<\/span> error:\n        print(error)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fifth, return the number of affected rows:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">return<\/span> affected_rows  <span class=\"hljs-comment\"># Return the number of affected rows<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Finally, call the update_book() function to update the book with id 37 with the new title:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\n    affected_rows = update_book(<span class=\"hljs-number\">37<\/span>, <span class=\"hljs-string\">'The Giant on the Hill *** TEST ***'<\/span>)\n    <span class=\"hljs-keyword\">print<\/span>(f<span class=\"hljs-string\">'Number of affected rows: {affected_rows}'<\/span>)\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\">Running the update<\/h2>\n\n\n\n<p>First, open the Command Prompt on Windows or Terminal on Unix-like systems:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">mysql -u root -p<\/code><\/span><\/pre>\n\n\n<p>Second, switch the current database to pub:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\"><span class=\"hljs-keyword\">USE<\/span> <span class=\"hljs-title\">pub<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PHP<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">php<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Third, retrieve the book with ID 37:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">SELECT<\/span> * <span class=\"hljs-keyword\">FROM<\/span> books\n<span class=\"hljs-keyword\">WHERE<\/span> <span class=\"hljs-keyword\">id<\/span> = <span class=\"hljs-number\">37<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-10\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+----+------------------------+---------------+\n| id | title                  | isbn          |\n+----+------------------------+---------------+\n| <span class=\"hljs-number\">37<\/span> | The Giant on the Hill  | <span class=\"hljs-number\">1235644620578<\/span> |\n+----+------------------------+---------------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.01 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-10\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Fourth, open the second terminal and execute the <code>update.py<\/code> module (note that you need to activate the virtual environment if relevant):<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-11\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\">python update.py<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-11\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">SQL (Structured Query Language)<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">sql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-12\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-built_in\">Number<\/span> <span class=\"hljs-keyword\">of<\/span> affected rows: <span class=\"hljs-number\">1<\/span><\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-12\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Finally, go back to the mysql terminal and retrieve the book with id 37 to verify the update:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">SELECT * FROM books\nWHERE id = 37;<\/code><\/span><\/pre>\n\n\n<p>Output:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-13\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">+----+------------------------------------+---------------+\n| id | title                              | isbn          |\n+----+------------------------------------+---------------+\n| <span class=\"hljs-number\">37<\/span> | The Giant on the Hill *** TEST *** | <span class=\"hljs-number\">1235644620578<\/span> |\n+----+------------------------------------+---------------+\n<span class=\"hljs-number\">1<\/span> row <span class=\"hljs-keyword\">in<\/span> <span class=\"hljs-keyword\">set<\/span> (0.00 sec)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-13\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">JavaScript<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">javascript<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The output indicates that the <code>update.py<\/code> program has updated the book ID 37 successfully.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Summary<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use the <code>execute()<\/code> method of the cursor object to run an update statement and call the commit of the connection object to apply the changes to the database.<\/li>\n<\/ul>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful? <\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"3297\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/\"\n\t\t\t\tdata-post-title=\"Python MySQL &#8211; Update Data in a Table\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"3297\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/\"\n\t\t\t\tdata-post-title=\"Python MySQL &#8211; Update Data in a Table\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial walks you through steps required to update data in MySQL table by using MySQL Connector\/Python API.<\/p>\n","protected":false},"author":2,"featured_media":3321,"parent":3229,"menu_order":4,"comment_status":"closed","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-3297","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 - Update Data From a Table from Python<\/title>\n<meta name=\"description\" content=\"This tutorial walks you through steps required to update data in a table from a Python program using MySQL Connector\/Python API.\" \/>\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\/python-mysql-update-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python MySQL - Update Data From a Table from Python\" \/>\n<meta property=\"og:description\" content=\"This tutorial walks you through steps required to update data in a table from a Python program using MySQL Connector\/Python API.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-03T04:28:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-update.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"195\" \/>\n\t<meta property=\"og:image:height\" content=\"138\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 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\\\/python-mysql-update-data\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-update-data\\\/\",\"name\":\"Python MySQL - Update Data From a Table from Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-update-data\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-update-data\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-update.jpg\",\"datePublished\":\"2014-10-23T02:55:39+00:00\",\"dateModified\":\"2024-01-03T04:28:48+00:00\",\"description\":\"This tutorial walks you through steps required to update data in a table from a Python program using MySQL Connector\\\/Python API.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-update-data\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-update-data\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-update-data\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-update.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-update.jpg\",\"width\":195,\"height\":138},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-update-data\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python MySQL\",\"item\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python MySQL &#8211; Update Data in a Table\"}]},{\"@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 - Update Data From a Table from Python","description":"This tutorial walks you through steps required to update data in a table from a Python program using MySQL Connector\/Python API.","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\/python-mysql-update-data\/","og_locale":"en_US","og_type":"article","og_title":"Python MySQL - Update Data From a Table from Python","og_description":"This tutorial walks you through steps required to update data in a table from a Python program using MySQL Connector\/Python API.","og_url":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-03T04:28:48+00:00","og_image":[{"width":195,"height":138,"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-update.jpg","type":"image\/jpeg"}],"twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/","url":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/","name":"Python MySQL - Update Data From a Table from Python","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-update.jpg","datePublished":"2014-10-23T02:55:39+00:00","dateModified":"2024-01-03T04:28:48+00:00","description":"This tutorial walks you through steps required to update data in a table from a Python program using MySQL Connector\/Python API.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-update.jpg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-update.jpg","width":195,"height":138},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-update-data\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.mysqltutorial.org\/"},{"@type":"ListItem","position":2,"name":"Python MySQL","item":"https:\/\/www.mysqltutorial.org\/python-mysql\/"},{"@type":"ListItem","position":3,"name":"Python MySQL &#8211; Update Data in a Table"}]},{"@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\/3297","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=3297"}],"version-history":[{"count":4,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3297\/revisions"}],"predecessor-version":[{"id":14046,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3297\/revisions\/14046"}],"up":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3229"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media\/3321"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=3297"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}