{"id":3278,"date":"2014-10-21T20:43:26","date_gmt":"2014-10-22T04:43:26","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=3278"},"modified":"2024-01-03T00:50:29","modified_gmt":"2024-01-03T07:50:29","slug":"python-mysql-blob","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/","title":{"rendered":"Python MySQL &#8211; Read &#038; Update BLOB in MySQL Database"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to work with <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-blob\/\">MySQL BLOB<\/a> data in Python including updating and reading <code>BLOB<\/code> data.<\/p>\n\n\n\n<p class=\"note\">This tutorial picks up where the <a href=\"https:\/\/www.mysqltutorial.org\/python-mysql\/calling-mysql-stored-procedures-python\/\">Calling Stored Procedures in Python<\/a>\u00a0tutorial left off.<\/p>\n\n\n\n<p>The&nbsp; <code>authors<\/code> table has a column named&nbsp;<code>photo<\/code> whose data type is <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-blob\/\">BLOB<\/a>. We will read data from an image and update it to the <code>photo<\/code> column.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Updating BLOB data in Python<\/h2>\n\n\n\n<p>The following program reads data from a file and updates it to the database:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">from mysql.connector import MySQLConnection, Error\r\nfrom config import read_config\r\n\r\n\r\ndef read_file(filename):\r\n    with open(filename, <span class=\"hljs-string\">'rb'<\/span>) <span class=\"hljs-keyword\">as<\/span> f:\r\n        photo = f.read()\r\n        <span class=\"hljs-keyword\">return<\/span> photo\r\n\r\n\r\ndef update_blob(author_id, filename):\r\n    <span class=\"hljs-comment\"># Read file data<\/span>\r\n    data = read_file(filename)\r\n\r\n    <span class=\"hljs-comment\"># Prepare update query and data<\/span>\r\n    query = <span class=\"hljs-string\">\"UPDATE authors \"<\/span> \\\r\n            <span class=\"hljs-string\">\"SET photo = %s \"<\/span> \\\r\n            <span class=\"hljs-string\">\"WHERE id  = %s\"<\/span>\r\n\r\n    args = (data, author_id)\r\n\r\n    config = read_config()\r\n\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        <span class=\"hljs-comment\"># Establish a connection to the MySQL database<\/span>\r\n        with MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\r\n            <span class=\"hljs-comment\"># Create a cursor to execute SQL queries<\/span>\r\n            with conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\r\n                <span class=\"hljs-comment\"># Execute the update query with the provided arguments<\/span>\r\n                cursor.execute(query, args)\r\n                <span class=\"hljs-comment\"># Commit the changes to the database<\/span>\r\n                conn.commit()\r\n\r\n    except Error <span class=\"hljs-keyword\">as<\/span> e:\r\n        <span class=\"hljs-keyword\">print<\/span>(e)\r\n\r\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        author_id = <span class=\"hljs-number\">3<\/span>  \r\n        filename = <span class=\"hljs-string\">'images\/francis_tugwell.png'<\/span> \r\n        update_blob(author_id, filename)\r\n    except Error <span class=\"hljs-keyword\">as<\/span> e:\r\n        <span class=\"hljs-keyword\">print<\/span>(e)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><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>How it works.<\/p>\n\n\n\n<p>First, define a function called <code>read_file()<\/code> that reads a file and returns the file&#8217;s content:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">read_file<\/span><span class=\"hljs-params\">(filename)<\/span>:<\/span>\r\n    <span class=\"hljs-keyword\">with<\/span> open(filename, <span class=\"hljs-string\">'rb'<\/span>) <span class=\"hljs-keyword\">as<\/span> f:\r\n        photo = f.read()\r\n        <span class=\"hljs-keyword\">return<\/span> photo<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><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>Second, create a new function called <code>update_blob()<\/code> that updates the photo for an author specified by <code>author_id<\/code> .<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">update_blob<\/span><span class=\"hljs-params\">(author_id, filename)<\/span>:<\/span>\r\n    <span class=\"hljs-comment\"># Read file data<\/span>\r\n    data = read_file(filename)\r\n\r\n    <span class=\"hljs-comment\"># Prepare update query and data<\/span>\r\n    query = <span class=\"hljs-string\">\"UPDATE authors \"<\/span> \\\r\n            <span class=\"hljs-string\">\"SET photo = %s \"<\/span> \\\r\n            <span class=\"hljs-string\">\"WHERE id  = %s\"<\/span>\r\n\r\n    args = (data, author_id)\r\n\r\n    config = read_config()\r\n\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        <span class=\"hljs-comment\"># Establish a connection to the MySQL database<\/span>\r\n        <span class=\"hljs-keyword\">with<\/span> MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\r\n            <span class=\"hljs-comment\"># Create a cursor to execute SQL queries<\/span>\r\n            <span class=\"hljs-keyword\">with<\/span> conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\r\n                <span class=\"hljs-comment\"># Execute the update query with the provided arguments<\/span>\r\n                cursor.execute(query, args)\r\n                <span class=\"hljs-comment\"># Commit the changes to the database<\/span>\r\n                conn.commit()\r\n\r\n    <span class=\"hljs-keyword\">except<\/span> Error <span class=\"hljs-keyword\">as<\/span> e:\r\n        print(e)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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<ul class=\"wp-block-list\">\n<li>First, call the\u00a0<code>read_file()<\/code> function to read data from a file and return the binary data.<\/li>\n\n\n\n<li>Second, compose an <a title=\"PHP MySQL Update Data\" href=\"https:\/\/www.mysqltutorial.org\/php-mysql\/php-mysql-update-data\/\">UPDATE statement<\/a> that updates <code>photo<\/code> column for an author specified by <code>author_id<\/code> . The <code>args<\/code> variable is a tuple that contains file data and <code>author_id<\/code>. We will pass this variable to the&nbsp;<code>execute()<\/code> method together with the <code>query<\/code> .<\/li>\n\n\n\n<li>Third, inside the\u00a0 <code>try...except<\/code> block, connect to the database, create a cursor, and execute the query with <code>args<\/code> . To apply the permanent change to the database, call the <code>commit()<\/code> method of the <code>MySQLConnection<\/code> object.<\/li>\n\n\n\n<li>Finally, close the cursor and database connection in the\u00a0 <code>finally<\/code> block.<\/li>\n<\/ul>\n\n\n\n<p>Third, use the\u00a0<code>update_blob()<\/code> function to read an image (<code>images\/francis_tugwell.png<\/code>) from the <code>images<\/code> directory of the project directory:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        author_id = <span class=\"hljs-number\">3<\/span>  \r\n        filename = <span class=\"hljs-string\">'images\/francis_tugwell.png'<\/span> \r\n        update_blob(author_id, filename)\r\n    <span class=\"hljs-keyword\">except<\/span> Error <span class=\"hljs-keyword\">as<\/span> e:\r\n        print(e)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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>Notice that you can download the following photo and place it in the <code>images<\/code> directory:<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"90\" height=\"105\" src=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2024\/01\/francis_tugwell.png\" alt=\"\" class=\"wp-image-14054\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Reading BLOB data in Python<\/h2>\n\n\n\n<p>The following program retrieves BLOB data from the\u00a0<code>authors<\/code> table and write it into a file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"PHP\" data-shcb-language-slug=\"php\"><span><code class=\"hljs language-php\">from mysql.connector import MySQLConnection, Error\r\nfrom config import read_config\r\n\r\ndef write_file(data, filename):\r\n    with open(filename, <span class=\"hljs-string\">'wb'<\/span>) <span class=\"hljs-keyword\">as<\/span> f:\r\n        f.write(data)\r\n\r\ndef read_blob(author_id, filename):\r\n    <span class=\"hljs-comment\"># Select the 'photo' column of a specific author<\/span>\r\n    query = <span class=\"hljs-string\">\"SELECT photo FROM authors WHERE id = %s\"<\/span>\r\n\r\n    <span class=\"hljs-comment\"># Read database configuration<\/span>\r\n    config = read_config()\r\n\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        <span class=\"hljs-comment\"># Establish a connection to the MySQL database<\/span>\r\n        with MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\r\n            <span class=\"hljs-comment\"># Create a cursor to execute SQL queries<\/span>\r\n            with conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\r\n                <span class=\"hljs-comment\"># Execute the query to retrieve the blob data<\/span>\r\n                cursor.execute(query, (author_id,))\r\n                \r\n                <span class=\"hljs-comment\"># Fetch the blob data from the result set<\/span>\r\n                photo = cursor.fetchone()&#91;<span class=\"hljs-number\">0<\/span>]\r\n\r\n                <span class=\"hljs-comment\"># Write the blob data into a file<\/span>\r\n                write_file(photo, filename)\r\n\r\n    except Error <span class=\"hljs-keyword\">as<\/span> e:\r\n        <span class=\"hljs-keyword\">print<\/span>(e)        \r\n\r\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        author_id = <span class=\"hljs-number\">3<\/span>\r\n        filename = <span class=\"hljs-string\">'images\/3.png'<\/span>\r\n        read_blob(author_id, filename)\r\n    except Error <span class=\"hljs-keyword\">as<\/span> e:\r\n        <span class=\"hljs-keyword\">print<\/span>(e)        <\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><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>How it works.<\/p>\n\n\n\n<p>First, define a <code>write_file()<\/code> function that writes binary data into a file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">write_file<\/span><span class=\"hljs-params\">(data, filename)<\/span>:<\/span>\n    <span class=\"hljs-keyword\">with<\/span> open(filename, <span class=\"hljs-string\">'wb'<\/span>) <span class=\"hljs-keyword\">as<\/span> f:\n        f.write(data)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><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>Second, create a new function called <code>read_blob()<\/code> that retrieves BLOB data from the database:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">read_blob<\/span><span class=\"hljs-params\">(author_id, filename)<\/span>:<\/span>\r\n    <span class=\"hljs-comment\"># Select the 'photo' column of a specific author<\/span>\r\n    query = <span class=\"hljs-string\">\"SELECT photo FROM authors WHERE id = %s\"<\/span>\r\n\r\n    <span class=\"hljs-comment\"># Read database configuration<\/span>\r\n    config = read_config()\r\n\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        <span class=\"hljs-comment\"># Establish a connection to the MySQL database<\/span>\r\n        <span class=\"hljs-keyword\">with<\/span> MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\r\n            <span class=\"hljs-comment\"># Create a cursor to execute SQL queries<\/span>\r\n            <span class=\"hljs-keyword\">with<\/span> conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\r\n                <span class=\"hljs-comment\"># Execute the query to retrieve the blob data<\/span>\r\n                cursor.execute(query, (author_id,))\r\n                \r\n                <span class=\"hljs-comment\"># Fetch the blob data from the result set<\/span>\r\n                photo = cursor.fetchone()&#91;<span class=\"hljs-number\">0<\/span>]\r\n\r\n                <span class=\"hljs-comment\"># Write the blob data into a file<\/span>\r\n                write_file(photo, filename)\r\n\r\n    <span class=\"hljs-keyword\">except<\/span> Error <span class=\"hljs-keyword\">as<\/span> e:\r\n        print(e)        <\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><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>The&nbsp; <code>read_blob()<\/code> function reads <code>BLOB<\/code> data from the&nbsp; <code>authors<\/code> table and write it into a file specified by the&nbsp; <code>filename<\/code> parameter.<\/p>\n\n\n\n<p>Third, call the\u00a0<code>read_blob()<\/code> function to read the photo of the author id 3 and write it to a file:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"Python\" data-shcb-language-slug=\"python\"><span><code class=\"hljs language-python\"><span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        author_id = <span class=\"hljs-number\">3<\/span>\r\n        filename = <span class=\"hljs-string\">'images\/3.png'<\/span>\r\n        read_blob(author_id, filename)\r\n    <span class=\"hljs-keyword\">except<\/span> Error <span class=\"hljs-keyword\">as<\/span> e:\r\n        print(e)   <\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><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>If you find a picture in the project&#8217;s <code>images<\/code> directory, it indicates that you have successfully read the BLOB from the database.<\/p>\n\n\n\n<p>In this tutorial, you have learned how to read and write BLOB data in MySQL from Python.<\/p>\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=\"3278\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/\"\n\t\t\t\tdata-post-title=\"Python MySQL &#8211; Read &#038; Update BLOB in MySQL Database\"\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=\"3278\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/\"\n\t\t\t\tdata-post-title=\"Python MySQL &#8211; Read &#038; Update BLOB in MySQL Database\"\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 shows you how to work with MySQL BLOB data in Python, with examples of updating and reading BLOB data.<\/p>\n","protected":false},"author":2,"featured_media":3314,"parent":3229,"menu_order":7,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-3278","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>Working with MySQL BLOB in Python<\/title>\n<meta name=\"description\" content=\"This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and reading BLOB data.\" \/>\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-blob\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Working with MySQL BLOB in Python\" \/>\n<meta property=\"og:description\" content=\"This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and reading BLOB data.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-03T07:50:29+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-blob.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-blob\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-blob\\\/\",\"name\":\"Working with MySQL BLOB in Python\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-blob\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-blob\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-blob.jpg\",\"datePublished\":\"2014-10-22T04:43:26+00:00\",\"dateModified\":\"2024-01-03T07:50:29+00:00\",\"description\":\"This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and reading BLOB data.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-blob\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-blob\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-blob\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-blob.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-blob.jpg\",\"width\":195,\"height\":138,\"caption\":\"Python MySQL BLOB\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-blob\\\/#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; Read &#038; Update BLOB in MySQL Database\"}]},{\"@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":"Working with MySQL BLOB in Python","description":"This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and reading BLOB data.","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-blob\/","og_locale":"en_US","og_type":"article","og_title":"Working with MySQL BLOB in Python","og_description":"This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and reading BLOB data.","og_url":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-03T07:50:29+00:00","og_image":[{"width":195,"height":138,"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-blob.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-blob\/","url":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/","name":"Working with MySQL BLOB in Python","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-blob.jpg","datePublished":"2014-10-22T04:43:26+00:00","dateModified":"2024-01-03T07:50:29+00:00","description":"This tutorial shows you how to work with MySQL BLOB data in Python, with examples of updating and reading BLOB data.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-blob.jpg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-blob.jpg","width":195,"height":138,"caption":"Python MySQL BLOB"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-blob\/#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; Read &#038; Update BLOB in MySQL Database"}]},{"@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\/3278","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=3278"}],"version-history":[{"count":4,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3278\/revisions"}],"predecessor-version":[{"id":14056,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3278\/revisions\/14056"}],"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\/3314"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=3278"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}