{"id":3271,"date":"2014-10-21T18:39:09","date_gmt":"2014-10-22T02:39:09","guid":{"rendered":"http:\/\/www.mysqltutorial.org\/?page_id=3271"},"modified":"2024-01-02T20:41:08","modified_gmt":"2024-01-03T03:41:08","slug":"python-mysql-insert-data","status":"publish","type":"page","link":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/","title":{"rendered":"Python MySQL &#8211; Insert Data Into a Table"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you will learn how to insert data into 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\/\">Querying Data from a Table in Python<\/a>\u00a0tutorial left off.<\/p>\n\n\n\n<p>To insert new rows into a MySQL table, 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 database server<\/a> by creating a new <code>MySQLConnection<\/code> object.<\/li>\n\n\n\n<li>Second, create a <code>MySQLCursor<\/code> object from the <code>MySQLConnection<\/code> object.<\/li>\n\n\n\n<li>Third, execute the <code><a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-insert\/\">INSERT<\/a><\/code> statement to insert data into the table.<\/li>\n\n\n\n<li>Finally, close the database connection.<\/li>\n<\/ul>\n\n\n\n<p>MySQL Connector\/Python provides an API that allows you to insert one or multiple rows into a table at a time. Let&#8217;s examine each method in more detail.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Insert one row into a table<\/h2>\n\n\n\n<p>The following program defines a function called <code>insert_book()<\/code> that inserts a new book into the <code>books<\/code> table:<\/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\r\n<span class=\"hljs-keyword\">from<\/span> config <span class=\"hljs-keyword\">import<\/span> read_config\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">insert_book<\/span><span class=\"hljs-params\">(title, isbn)<\/span>:<\/span>\r\n    query = <span class=\"hljs-string\">\"INSERT INTO books(title,isbn) \"<\/span> \\\r\n            <span class=\"hljs-string\">\"VALUES(%s,%s)\"<\/span>\r\n\r\n    args = (title, isbn)\r\n    book_id = <span class=\"hljs-literal\">None<\/span>\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        config = read_config()\r\n        <span class=\"hljs-keyword\">with<\/span> MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\r\n            <span class=\"hljs-keyword\">with<\/span> conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\r\n                cursor.execute(query, args)\r\n                book_id =  cursor.lastrowid\r\n            conn.commit()\r\n        <span class=\"hljs-keyword\">return<\/span> book_id\r\n    <span class=\"hljs-keyword\">except<\/span> Error <span class=\"hljs-keyword\">as<\/span> error:\r\n        print(error)\r\n\r\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\r\n    insert_book(<span class=\"hljs-string\">'A Sudden Light'<\/span>, <span class=\"hljs-string\">'9781439187036'<\/span>)<\/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 the <code>MySQLConnection<\/code> and <code>Error<\/code> classes from the <code>mysql.connector<\/code> module, and <code>read_config<\/code> is a function imported from a custom module called <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 <code>insert_book()<\/code> that accepts two arguments: title and ISBN and prepare an SQL query to insert a new row into the books table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">def insert_book(title, isbn):\r\n    query = <span class=\"hljs-string\">\"INSERT INTO books(title,isbn) \"<\/span> \\\r\n            <span class=\"hljs-string\">\"VALUES(%s,%s)\"<\/span>\r\n    args = (title, isbn)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><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>Third, use the  <code>with<\/code> statement to open a database connection (<code>MySQLConnection<\/code>) and create a cursor (<code>cursor<\/code>).  We use the <code>**config<\/code> syntax to pass keyword arguments from the <code>config<\/code> dictionary:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\">    <span class=\"hljs-keyword\">try<\/span>:\r\n        config = read_config()\r\n        <span class=\"hljs-keyword\">with<\/span> MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\r\n            <span class=\"hljs-keyword\">with<\/span> conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><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, execute the query using the execute() method of the cursor with the provided arguments (args) and return the inserted id of the row:<\/p>\n\n\n<pre class=\"wp-block-code\"><span><code class=\"hljs\">                cursor.execute(query, args)\n                book_id =  cursor.lastrowid<\/code><\/span><\/pre>\n\n\n<p>Sixth, commit the changes to the database using the <code>commit()<\/code> method:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"CSS\" data-shcb-language-slug=\"css\"><span><code class=\"hljs language-css\">            <span class=\"hljs-selector-tag\">conn<\/span><span class=\"hljs-selector-class\">.commit<\/span>()<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">CSS<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">css<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Seventh, show the error message if it occurs during the execution:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-6\" 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:\r\n        print(error)<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-6\"><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 class=\"note\">Note that the <code>with<\/code> statement automatically takes care of closing the cursor and the database connection, even if an exception occurs.<\/p>\n\n\n\n<p>Finally, call the <code>insert_book()<\/code> function to insert a new book into the <code>books<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-7\" data-shcb-language-name=\"JavaScript\" data-shcb-language-slug=\"javascript\"><span><code class=\"hljs language-javascript\"><span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\r\n    insert_book(<span class=\"hljs-string\">'A Sudden Light'<\/span>, <span class=\"hljs-string\">'9781439187036'<\/span>)\r<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-7\"><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<h2 class=\"wp-block-heading\">Insert multiple rows into a table<\/h2>\n\n\n\n<p>The following <code>INSERT<\/code>&nbsp;statement allows you to <a href=\"https:\/\/www.mysqltutorial.org\/mysql-basics\/mysql-insert-multiple-rows\/\">insert multiple rows<\/a> into the <code>books<\/code> table:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-8\" data-shcb-language-name=\"SQL (Structured Query Language)\" data-shcb-language-slug=\"sql\"><span><code class=\"hljs language-sql\"><span class=\"hljs-keyword\">INSERT<\/span> <span class=\"hljs-keyword\">INTO<\/span> books(title,isbn)\n<span class=\"hljs-keyword\">VALUES<\/span>(<span class=\"hljs-string\">'Harry Potter And The Order Of The Phoenix'<\/span>, <span class=\"hljs-string\">'9780439358071'<\/span>),\n       (<span class=\"hljs-string\">'Gone with the Wind'<\/span>, <span class=\"hljs-string\">'9780446675536'<\/span>),\n       (<span class=\"hljs-string\">'Pride and Prejudice (Modern Library Classics)'<\/span>, <span class=\"hljs-string\">'9780679783268'<\/span>);<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-8\"><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>To insert multiple rows into a table from Python, you use the\u00a0 <code>executemany()<\/code> method of the <code>MySQLCursor<\/code> object. <\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-9\" 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\r\n<span class=\"hljs-keyword\">from<\/span> config <span class=\"hljs-keyword\">import<\/span> read_config\r\n\r\n<span class=\"hljs-function\"><span class=\"hljs-keyword\">def<\/span> <span class=\"hljs-title\">insert_books<\/span><span class=\"hljs-params\">(books)<\/span>:<\/span>\r\n    query = <span class=\"hljs-string\">\"INSERT INTO books(title,isbn) \"<\/span> \\\r\n            <span class=\"hljs-string\">\"VALUES(%s,%s)\"<\/span>\r\n    <span class=\"hljs-keyword\">try<\/span>:\r\n        config = read_config()\r\n        <span class=\"hljs-keyword\">with<\/span> MySQLConnection(**config) <span class=\"hljs-keyword\">as<\/span> conn:\r\n            <span class=\"hljs-keyword\">with<\/span> conn.cursor() <span class=\"hljs-keyword\">as<\/span> cursor:\r\n                cursor.executemany(query, books)\r\n            conn.commit()\r\n    <span class=\"hljs-keyword\">except<\/span> Error <span class=\"hljs-keyword\">as<\/span> error:\r\n        print(error)\r\n\r\n<span class=\"hljs-keyword\">if<\/span> __name__ == <span class=\"hljs-string\">'__main__'<\/span>:\r\n    books = &#91;(<span class=\"hljs-string\">'Harry Potter And The Order Of The Phoenix'<\/span>, <span class=\"hljs-string\">'9780439358071'<\/span>),\r\n             (<span class=\"hljs-string\">'Gone with the Wind'<\/span>, <span class=\"hljs-string\">'9780446675536'<\/span>),\r\n             (<span class=\"hljs-string\">'Pride and Prejudice (Modern Library Classics)'<\/span>, <span class=\"hljs-string\">'9780679783268'<\/span>)]\r\n    insert_books(books)\r\n<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-9\"><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 logic in this example is similar to the logic in the first example. However, instead of calling the\u00a0 <code>execute()<\/code> method, we call <code>executemany()<\/code> method.<\/p>\n\n\n\n<p>To insert multiple rows into the books table, we pass a list of tuples, each containing the title and ISBN of the book to the <code>insert_books()<\/code> function.<\/p>\n\n\n\n<p>By calling the <code>executemany()<\/code> method of the <code>MySQLCursor<\/code> object, the MySQL Connector\/Python translates the\u00a0<code>INSERT<\/code> statement into the one that contains multiple lists of values.<\/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 to execute an <code>INSERT<\/code> statement that inserts one row into a table.<\/li>\n\n\n\n<li>Use the <code>executeMany()<\/code> method to execute an <code>INSERT<\/code> statement that inserts multiple rows into a table.<\/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=\"3271\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/\"\n\t\t\t\tdata-post-title=\"Python MySQL &#8211; Insert Data Into 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=\"3271\"\n\t\t\t\tdata-post-url=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/\"\n\t\t\t\tdata-post-title=\"Python MySQL &#8211; Insert Data Into 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>In this tutorial, you will learn how to insert data into a table using MySQL Connector\/Python API.<\/p>\n","protected":false},"author":2,"featured_media":3318,"parent":3229,"menu_order":3,"comment_status":"open","ping_status":"open","template":"","meta":{"footnotes":""},"class_list":["post-3271","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 - Insert Data Into a Table Examples<\/title>\n<meta name=\"description\" content=\"In this tutorial, you will learn how to insert one or multiple rows into a table 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-insert-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python MySQL - Insert Data Into a Table Examples\" \/>\n<meta property=\"og:description\" content=\"In this tutorial, you will learn how to insert one or multiple rows into a table using MySQL Connector\/Python API.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/\" \/>\n<meta property=\"og:site_name\" content=\"MySQL Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2024-01-03T03:41:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-insert.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=\"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\\\/python-mysql-insert-data\\\/\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-insert-data\\\/\",\"name\":\"Python MySQL - Insert Data Into a Table Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-insert-data\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-insert-data\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-insert.jpg\",\"datePublished\":\"2014-10-22T02:39:09+00:00\",\"dateModified\":\"2024-01-03T03:41:08+00:00\",\"description\":\"In this tutorial, you will learn how to insert one or multiple rows into a table using MySQL Connector\\\/Python API.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-insert-data\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-insert-data\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-insert-data\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-insert.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mysqltutorial.org\\\/wp-content\\\/uploads\\\/2014\\\/10\\\/mysql-python-insert.jpg\",\"width\":195,\"height\":138},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mysqltutorial.org\\\/python-mysql\\\/python-mysql-insert-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; Insert Data Into 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 - Insert Data Into a Table Examples","description":"In this tutorial, you will learn how to insert one or multiple rows into a table 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-insert-data\/","og_locale":"en_US","og_type":"article","og_title":"Python MySQL - Insert Data Into a Table Examples","og_description":"In this tutorial, you will learn how to insert one or multiple rows into a table using MySQL Connector\/Python API.","og_url":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/","og_site_name":"MySQL Tutorial","article_modified_time":"2024-01-03T03:41:08+00:00","og_image":[{"width":195,"height":138,"url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-insert.jpg","type":"image\/jpeg"}],"twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/","url":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/","name":"Python MySQL - Insert Data Into a Table Examples","isPartOf":{"@id":"https:\/\/www.mysqltutorial.org\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/#primaryimage"},"image":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-insert.jpg","datePublished":"2014-10-22T02:39:09+00:00","dateModified":"2024-01-03T03:41:08+00:00","description":"In this tutorial, you will learn how to insert one or multiple rows into a table using MySQL Connector\/Python API.","breadcrumb":{"@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-data\/#primaryimage","url":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-insert.jpg","contentUrl":"https:\/\/www.mysqltutorial.org\/wp-content\/uploads\/2014\/10\/mysql-python-insert.jpg","width":195,"height":138},{"@type":"BreadcrumbList","@id":"https:\/\/www.mysqltutorial.org\/python-mysql\/python-mysql-insert-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; Insert Data Into 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\/3271","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=3271"}],"version-history":[{"count":4,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3271\/revisions"}],"predecessor-version":[{"id":14035,"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/pages\/3271\/revisions\/14035"}],"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\/3318"}],"wp:attachment":[{"href":"https:\/\/www.mysqltutorial.org\/wp-json\/wp\/v2\/media?parent=3271"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}