{"id":3915,"date":"2018-11-28T10:59:23","date_gmt":"2018-11-28T02:59:23","guid":{"rendered":"https:\/\/dmesg.app\/?p=3915"},"modified":"2019-03-01T16:39:35","modified_gmt":"2019-03-01T08:39:35","slug":"one-million-data","status":"publish","type":"post","link":"https:\/\/dmesg.app\/one-million-data.html","title":{"rendered":"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09"},"content":{"rendered":"<div  class=\"sc_act\">\u8fd9\u7bc7\u6587\u7ae0\u5728 2019\u5e7403\u670801\u65e516:39:35 \u66f4\u65b0\u4e86\u54e6~<\/div><p><span style=\"font-size: 12pt;\">\u5f88\u957f\u65f6\u95f4\u4e4b\u524d\u6211\u5199\u8fc7\u4e00\u7bc7<a href=\"https:\/\/dmesg.app\/mysql-es-mongo.html\">\u300a\u4f7f\u7528<\/a><a href=\"https:\/\/dmesg.app\/mysql-es-mongo.html\"> Python \u5c06\u6d77\u91cf MySQL \u6570\u636e\u5bfc\u5165 Elastic Search\/MongoDB<\/a><a href=\"https:\/\/dmesg.app\/mysql-es-mongo.html\">\u300b<\/a>\uff0c\u4e3b\u8981\u5c31\u8bf4\u4e86\u5982\u4f55\u628a\u5927\u91cfMySQL\u6570\u636e\u5199\u5165\u952e\u503c\u5bf9\u6570\u636e\u5e93\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u73b0\u5728\u56de\u8fc7\u5934\u770b\u6765\u8fd9\u7bc7\u6587\u7ae0\u8fd8\u662f\u5f88\u6709\u53c2\u8003\u4ef7\u503c\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6709\u7684\u65f6\u5019\u6211\u4eec\u4f1a\u9047\u5230\u76f8\u53cd\u7684\u9700\u6c42\uff0c\u6bd4\u5982\u8bf4\u628a\u5bf9\u5e94\u7684\u952e\u503c\u5bf9\u6570\u636e\u5e93\uff08\u6216\u8005\u8bf4\u662fjson\u6587\u4ef6\uff09\u5bfc\u5165\uff08\u5217\u6570\u636e\u7c7b\u578b\u76f8\u7b26\uff09\u7684MySQL\u8868\u4e2d\u3002\u901a\u5e38\u6765\u8bf4\u8fd9\u4e0d\u662f\u4e2a\u5565\u5927\u95ee\u9898\uff0c\u6839\u636ejson\u63d0\u53d6\u51fa\u5217\uff0c\u751f\u6210SQL\u8bed\u53e5\u5c31\u53ef\u4ee5\u4e86\u3002\u4e5f\u5c31\u8fd9\u4e48\u51e0\u884c\uff0c\u7136\u540eexecute\u52a0\u53c2\u6570\u5c31\u53ef\u4ee5\u4e86\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">placeholders = &#039;, &#039;.join([&#039;%s&#039;] * len(raw_dict))\r\ncolumns = &#039;, &#039;.join(raw_dict.keys())\r\ninsert_sql = &quot;INSERT INTO %s ( %s ) VALUES ( %s )&quot; % (insert_table, columns, placeholders)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u5f53\u7136\u4e86\u4f60\u8981\u662f\u60f3\u76f4\u63a5\u751f\u6210\u80fd\u7528\u7684sql\u8bed\u53e5\u90a3\u6211\u4e5f\u6ca1\u610f\u89c1\uff08\u5e76\u629b\u51fa\u4e00\u4e2a?\u7684\u8868\u60c5\uff09<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5927\u91cf\u63d2\u5165\u6570\u636e\u7684\u65f6\u5019\u548b\u6574\u5462\uff1f<\/span><\/p>\n<h1><span style=\"font-size: 12pt;\">\u9996\u5148\u6211\u4eec\u2026\u2026<\/span><\/h1>\n<p><span style=\"font-size: 12pt;\">\u9996\u5148\u6211\u4eec\u8981\u77e5\u9053\uff0c\u6027\u80fd\u662f\u7531\u591a\u65b9\u9762\u56e0\u7d20\u51b3\u5b9a\u7684\uff0c\u6bd4\u5982\u8bf4\u4ee3\u7801\u6548\u7387\u8d28\u91cf\u3001Python\u6027\u80fd\u3001\u670d\u52a1\u5668\u6027\u80fd\uff08\u5305\u542bMySQL\u7248\u672c\uff0c\u7f16\u8bd1\u4f18\u5316\uff0c\u5bbf\u4e3b\u673aIO\/CPU\/RAM\u7b49\uff09\u3001\u8868\u7ed3\u6784\u7684\u8bbe\u8ba1\u3001\u7f51\u7edc\u901f\u5ea6\u7b49\uff0c\u54b1\u8981\u627e\u5230\u77ed\u677f\u624d\u53ef\u4ee5\u3002\u4e3a\u4e86\u627e\u5230\u77ed\u677f\uff0c\u9700\u8981\u4f7f\u7528\u63a7\u5236\u53d8\u91cf\u6cd5\uff0c\u4f46\u662f\u6709\u4e9b\u53d8\u91cf\u4e0d\u53ef\u63a7\uff0c\u90a3\u5c31\u5f88\u4e0d\u597d\u529e\u4e86\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u7136\u540e\u6211\u9700\u8981\u9001\u4e0aMySQL\u5b98\u65b9\u6587\u6863\u4e24\u7bc7\uff0c\u8bf4\u7684\u975e\u5e38\u8be6\u7ec6\u4e86\uff0c\u6211\u7b80\u5355\u603b\u7ed3\u4e0b<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">Optimizing INSERT Statements: <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/insert-optimization.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/insert-optimization.html<\/a><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">Bulk Data Loading for InnoDB Tables: <a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/optimizing-innodb-bulk-data-loading.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/optimizing-innodb-bulk-data-loading.html<\/a><\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u4f18\u5316INSERT\u8bed\u53e5<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u63d2\u5165\u65f6\u95f4\u7531\u4ee5\u4e0b\u56e0\u7d20\u51b3\u5b9a\uff0c\u6570\u5b57\u4ee3\u8868\u6743\u91cd<\/span><\/p>\n<ul>\n<li><span style=\"font-size: 12pt;\">Connecting: (3)<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Sending query to server: (2)<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Parsing query: (2)<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Inserting row: (1 \u00d7 size of row)<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Inserting indexes: (1 \u00d7 number of indexes)<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Closing: (1)<\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: 12pt;\">\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u65b9\u5f0f\u52a0\u901f\u63d2\u5165\uff1a<\/span><\/p>\n<ul>\n<li><span style=\"font-size: 12pt;\">\u5982\u679c\u4ece\u540c\u4e00\u4e2a\u5ba2\u6237\u7aef\u540c\u65f6\u63d2\u5165\uff0c\u4f7f\u7528\u591a\u503c\u7684INSERT\u8bed\u53e5\u4e00\u6b21\u6027\u63d2\u5165\u591a\u884c\uff0c\u8fd9\u6bd4\u4f7f\u7528\u5355\u884c\u7684INSERT\u8bed\u53e5\u8981\u5feb\u5f97\u591a\u3002\u5982\u679c\u8981\u5c06\u6570\u636e\u6dfb\u52a0\u5230\u975e\u7a7a\u8868\u4e2d\uff0c\u5219\u53ef\u4ee5\u8c03\u6574\u8be5 <code>bulk_insert_buffer_size <\/code>\u53d8\u91cf\u4ee5\u4f7f\u6570\u636e\u63d2\u5165\u901f\u5ea6\u66f4\u5feb\u3002<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">\u4ece\u6587\u672c\u6587\u4ef6\u52a0\u8f7d\u8868\u683c\u65f6\uff0c\u8bf7\u4f7f\u7528\u00a0<code>LOAD DATA INFILE<\/code>\u3002\u8fd9\u901a\u5e38\u6bd4\u4f7f\u7528INSERT\u8bed\u53e5\u5feb20\u500d<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">\u5229\u7528\u5217\u5177\u6709\u9ed8\u8ba4\u503c\u7684\u4e8b\u5b9e\u3002\u53ea\u6709\u5f53\u8981\u63d2\u5165\u7684\u503c\u4e0d\u540c\u4e8e\u9ed8\u8ba4\u503c\u65f6\u624d\u663e\u5f0f\u63d2\u5165\u503c\u3002\u8fd9\u51cf\u5c11\u4e86MySQL\u5fc5\u987b\u6267\u884c\u7684\u89e3\u6790\u5e76\u63d0\u9ad8\u4e86\u63d2\u5165\u901f\u5ea6\u3002<\/span><\/li>\n<\/ul>\n<h2><span style=\"font-size: 12pt;\">InnoDB\u8868\u7684\u6279\u91cf\u6570\u636e\u52a0\u8f7d<\/span><\/h2>\n<h3><span style=\"font-size: 12pt;\">\u5173\u95ed\u81ea\u52a8\u63d0\u4ea4<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u5173\u95ed\u81ea\u52a8\u63d0\u4ea4\uff0c\u56e0\u4e3a\u5b83\u4e3a\u6bcf\u4e2a\u64cd\u4f5c\u6267\u884c\u65e5\u5fd7\u5237\u65b0\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5b9e\u9645\u4e0a\u9ed8\u8ba4\u60c5\u51b5\u4e0bpymysql\u5e2e\u6211\u4eec\u505a\u4e86\uff0c<\/span><code>set autocommit=0<\/code><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5173\u95ed\u552f\u4e00\u6027\u6821\u9a8c<\/span><\/h3>\n<pre class=\"prettyprint linenums\">set unique checks = 0\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u5bf9\u4e8e\u5927\u8868\u800c\u8a00\u8fd9\u4f1a\u8282\u7ea6\u5f88\u591a\u78c1\u76d8IO\uff0c\u4e0d\u8fc7\u8981\u786e\u4fdd\u6570\u636e\u6ca1\u6709\u91cd\u590d\u8bb0\u5f55\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5173\u95ed\u5916\u952e\u6821\u9a8c<\/span><\/h3>\n<pre class=\"prettyprint linenums\">SET foreign_key_checks=0;\r\n<\/pre>\n<h3><span style=\"font-size: 12pt;\">\u591a\u503cINSERT<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u4f7f\u7528\u591a\u503cINSERT \u6765\u51cf\u5c11\u5ba2\u6237\u7aef\u4e0e\u670d\u52a1\u5668\u4e4b\u95f4\u7684\u901a\u4fe1\u5f00\u9500<\/span><\/p>\n<pre class=\"prettyprint linenums\">INSERT INTO yourtable VALUES (1,2), (5,5), ...;\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0cMyISAM\u7528\u8fd9\u62db\u4e5f\u7ba1\u7528\u3002<\/span><\/p>\n<p><strong><span style=\"font-size: 12pt;\">\u8fd9\u4e00\u70b9\u662f\u6211\u4eec\u672c\u6587\u8ba8\u8bba\u7684\u91cd\u70b9\u5185\u5bb9\u3002<\/span><\/strong><\/p>\n<h3><span style=\"font-size: 12pt;\">\u81ea\u589e\u5217\u7684\u5904\u7406<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u5f53\u5bf9\u5177\u6709\u81ea\u52a8\u589e\u91cf\u5217\u7684\u8868\u8fdb\u884c\u6279\u91cf\u63d2\u5165\u65f6\uff0c\u8bf7\u5c06\u5176\u8bbe\u7f6e<code>\u00a0innodb_autoinc_lock_mode<\/code>\u4e3a2\u800c\u4e0d\u662f\u9ed8\u8ba4\u503c1<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u4e3b\u952e\u6392\u5e8f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">InnoDB\u8868\u662f\u6309\u7167\u4e3b\u952e\u987a\u5e8f\u6392\u5217\u7684\uff0c\u6240\u4ee5\u5c06\u6570\u636e\u987a\u5e8f\u6309\u7167\u4e3b\u952e\u987a\u5e8f\u6392\u5217\u597d\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5bfc\u5165\u6548\u7387<\/span><\/p>\n<h1><span style=\"font-size: 12pt;\">Python\u6027\u80fd<\/span><\/h1>\n<p><span style=\"font-size: 12pt;\"><del datetime=\"2018-11-27T01:52:44+00:00\">\u8fd9\u53ef\u80fd\u662fPHP\u88ab\u9ed1\u7684\u6700\u60e8\u7684\u4e00\u6b21\u3002<\/del><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5982\u679c\u5355\u7eaf\u7684\u6bd4\u8f83\u6267\u884c\u6027\u80fd\u7684\u8bdd\uff0cPython\u662f\u80af\u5b9a\u6bd4\u4e0d\u8fc7\u9759\u6001\u8bed\u8a00\u7684\u3002<s>\u4e0d\u8fc7\u6211\u65e9\u5c31\u8fc7\u4e86\u5355\u7eaf\u7684\u5e74\u9f84\uff0c\u6211\u5f88\u90aa\u6076\u7684\u3002<\/s>\u7531\u4e8e\u8fd9\u662fPython\u81ea\u8eab\u7684\u77ed\u677f\uff0c\u54b1\u4e5f\u4e0d\u592a\u597d\u505a\u70b9\u4ec0\u4e48\u6709\u5b9e\u8d28\u6027\u7684\u5de5\u4f5c\uff0c\u4e5f\u8bb8\u4ec5\u9650\u4e8e\u628a\u89e3\u91ca\u5668\u6362\u6210PyPy\uff0c\u7f16\u8bd1Python\u65f6\u5e26\u4e0a<code>enable-optimizations<\/code>\uff0c\u628a\u6027\u80fd\u5173\u952e\u7684\u6a21\u5757\u7528C\/C++\u5199\u4e00\u904d\u7136\u540e\u80f6\u6c34\u7cca\u4e0a\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4f46\u53ef\u662f\u554a\u53ef\u4f46\u662f\u554a\uff0c\u4ee3\u7801\u6267\u884c\u65f6\u7edd\u5927\u90e8\u5206\u7684\u65f6\u95f4\u90fd\u6d88\u8017\u5728\u4e86\u7f51\u7edcIO\u3001\u78c1\u76d8IO\uff0c\u5728\u8bed\u8a00\u672c\u8eab\u4e0a\u7684\u52a3\u52bf\u5e76\u4e0d\u662f\u90a3\u4e48\u660e\u663e\u3002\u5f53\u7136\u4e86\u975e\u5f97\u8bf4\u8bed\u8a00\u672c\u8eab\uff0c\u90a3\u52a8\u6001\u8bed\u8a00\u8fd0\u884c\u65f6\u8981\u89e3\u91ca\uff0c\u8981\u8fd0\u884c\u65f6\u68c0\u67e5\u2026\u2026<\/span><\/p>\n<h1><span style=\"font-size: 12pt;\">\u4ee3\u7801\u6548\u7387\u8d28\u91cf<\/span><\/h1>\n<p><span style=\"font-size: 12pt;\">\u5b9e\u9645\u4e0a\u8001\u5b9e\u8bf4\uff0c\u8fd9\u90e8\u5206\u624d\u662f\u6700\u5173\u952e\u7684\u3002\u4e00\u4e2a\u8db3\u591fPythonic\u7684\u4ee3\u7801\u770b\u8d77\u6765\u662f\u5f88\u8212\u670d\u7684\u55ef\u2026\u2026<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u67e5\u8be2<\/span><\/h2>\n<h3><span style=\"font-size: 12pt;\">\u67e5\u8be2\u65f6SQL\u6ce8\u5165\u7684\u9884\u9632<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u5728\u6709\u4e9b\u60c5\u51b5\u4e0b\uff08\u6bd4\u5982\u8bf4\u767b\u5f55\u7684\u65f6\u5019\uff09\u6211\u4eec\u9700\u8981\u8fdb\u884cwhere\u9650\u5236\u6761\u4ef6\u67e5\u8be2\uff0c\u6b64\u65f6\u5982\u679c\u4f7f\u7528\u62fc\u63a5SQL\u8bed\u53e5\u7684\u65b9\u5f0f\uff0c\u90a3\u4e48\u88ab\u6ce8\u5165\u51e0\u4e4e\u5c31\u662f\u80af\u5b9a\u7684\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6bd4\u5982\u67d0\u4e9b\u65b0\u624b\u5728\u767b\u5f55\u7684\u67e5\u8be2\u8bed\u53e5\u53ef\u80fd\u4f1a\u6784\u9020\u5982\u4e0b\u8bed\u53e5\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">SELECT * FROM account WHERE username=&#039;benny&#039; AND password=&#039;123456&#039;\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u5176\u4e2dbenny\u548c123456\u662f\u7531\u7528\u6237\u8f93\u5165\u7684\u53d8\u91cf\uff0c\u901a\u8fc7\u5224\u65ad\u7ed3\u679c\u96c6\u662f\u5426\u4e3a\u7a7a\u6765\u5224\u65ad\u662f\u5426\u767b\u5f55\u6210\u529f\u3002\u4e4d\u4e00\u770b\u4f3c\u4e4e\u6ca1\u5565\u95ee\u9898\uff0c\u4f46\u662f\u2026\u2026\u95ee\u9898\u592a\u591a\u4e86\u3002<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 12pt;\">\u65e0\u9a8c\u8bc1\u767b\u5f55<\/span><\/li>\n<\/ol>\n<p><span style=\"font-size: 12pt;\">\u6076\u610f\u7528\u6237\u53ea\u9700\u8981\u628a\u7528\u6237\u540d\u8f93\u5165\u4e3a<code>' or 1=1; --<\/code> \uff0cSQL\u8bed\u53e5\u5c31\u4f1a\u53d8\u6210\u8fd9\u6837\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">SELECT * FROM account WHERE username=&#039;&#039; or 1=1; -- &#039; AND password=&#039;123456&#039;\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u662f\u4e00\u6761\u5e26\u4e0d\u5e26WHERE\u90fd\u4e00\u6837\u7684\u8bed\u53e5\uff0c\u53ea\u8981\u8868\u4e2d\u6709\u6570\u636e\u90a3\u4e48\u7ed3\u679c\u96c6\u5c31\u4e00\u5b9a\u4e3a\u771f\uff0c\u81ea\u7136\u4e5f\u5c31\u7ed5\u8fc7\u767b\u5f55\u4e86\u3002<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 12pt;\">\u5404\u79cd\u6ce8\u5165<\/span><\/li>\n<\/ol>\n<p><span style=\"font-size: 12pt;\">\u901a\u8fc7\u6784\u9020\u5404\u79cd\u5404\u6837\u7684\u5947\u8469\u7684SQL\u8bed\u53e5\uff0c\u53ef\u4ee5\u6478\u7d22\u51fa\u6765\u8868\u7684\u7ed3\u6784\uff0c\u751a\u81f3\u662f\u67d0\u4e9b\u5173\u952e\u5e93\uff08\u6bd4\u5982mysql\u8fd9\u4e2a\u5e93\uff09\u7684\u6570\u636e\uff0c\u6bd4\u5982\u8bf4<a href=\"https:\/\/chybeta.github.io\/2017\/07\/21\/MySql%E6%B3%A8%E5%85%A5%E5%A4%87%E5%BF%98%E5%BD%95\/\">\u8fd9\u7bc7<\/a>\u3002<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 12pt;\">\u5bc6\u7801\u5b58\u50a8\u95ee\u9898<\/span><\/li>\n<\/ol>\n<p><span style=\"font-size: 12pt;\">\u5373\u4f7f\u6ce8\u5165\u4e0d\u662f\u95ee\u9898\uff0c\u4ece\u7cfb\u7edf\u8bbe\u8ba1\u7684\u89d2\u5ea6\u6765\u8bb2\u8fd9\u79cd\u8bbe\u8ba1\u4e5f\u662f\u9519\u8bef\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u660e\u6587\u5bc6\u7801\uff0c\u65e0\u8bba\u4ece\u4f20\u8f93\u89d2\u5ea6\u8fd8\u662f\u4ece\u6570\u636e\u5e93\u89d2\u5ea6\u6765\u8bb2\u90fd\u662f\u4e0d\u5408\u7406\u7684\u3002\u5373\u4f7f\u662f\u4f7f\u7528\u5b89\u5168\u7684\u6563\u5217\u51fd\u6570\u3001HMAC\u4e5f\u662f\u9519\u8bef\u7684\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6b63\u786e\u7684\u59ff\u52bf\u662f\u7528\u53c2\u6570\u5316\u67e5\u8be2\u67e5\u8be2\u51fa\u5bc6\u7801\uff0c\u4f7f\u7528PBKDF\u7684\u65b9\u6cd5\u8fdb\u884c\u7b49\u65f6\u95f4\u6bd4\u8f83\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\uff08\u5982\u4f55\u5b58\u50a8\u7528\u6237\u5bc6\u7801\u662f\u4e00\u95e8\u827a\u672f\uff0c\u4ee5\u540e\u4e5f\u8bb8\u5355\u72ec\u5f00\u4e00\u7bc7\u5b8c\u6574\u4ecb\u7ecd\u5427\uff09<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">dictCursor<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u6709\u4e9b\u65f6\u5019\u6211\u4eec\u53ef\u80fd\u9700\u8981\u67e5\u8be2\u51fa\u6765\u7684\u7ed3\u679c\u662f\u4e00\u5b9a\u7c7b\u578b\u7684\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0bpymysq\u4f7f\u7528\u7684cursor\u4f1a\u67e5\u8be2\u51fa\u6765<code>[(),()]<\/code>\u8fd9\u79cd\u683c\u5f0f\u7684\u6570\u636e\uff0c\u5982\u679c\u6211\u4eec\u9700\u8981\u5b57\u5178\u6837\u5f0f\u7684\u6570\u636e\uff0c\u90a3\u4e48\u5c31\u8981\u5728\u6784\u9020con\u8fde\u63a5\u5bf9\u8c61\u7684\u65f6\u5019\u6307\u5b9a\u6e38\u6807\uff0c\u8bed\u6cd5\u5927\u81f4\u5982\u4e0b\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">con = pymysql.connect(host=&#039;localhost&#039;, user=&#039;user&#039;, password=&#039;passwd&#039;,\r\ndb=&#039;db&#039;, charset=&#039;utf8mb4&#039;, cursorclass=pymysql.cursors.DictCursor)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u8fd9\u6837\u5c31\u4e0d\u7528\u518d\u4eceinformation_schema\u91cc\u4e71\u67e5\u4e00\u901a\u4e86\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">fetch\u65b9\u5f0f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">cur\u5728\u83b7\u53d6\u6570\u636e\u65f6\uff0c\u6709<code>fetchall()<\/code>\u3001<code>fetchone()<\/code>\u3001<code>fetchmany()<\/code>\u4e09\u79cd\u65b9\u6cd5\u3002\u7ec6\u8282\u5df2\u7ecf<a href=\"https:\/\/dmesg.app\/mysql-es-mongo.html\">\u5728\u8fd9\u91cc\u8bf4\u4e86<\/a>\uff0c\u6240\u4ee5\u5c31\u6682\u4e14\u4e0d\u63d0\u3002<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u63d2\u5165<\/span><\/h2>\n<h3><span style=\"font-size: 12pt;\">\u63d2\u5165\u65f6SQL\u6ce8\u5165\u7684\u9884\u9632<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u63d2\u5165\u6570\u636e\u65f6\u4e5f\u540c\u6837\u9700\u8981\u9632\u8303SQL\u6ce8\u5165\uff0c\u6240\u4ee5\u5e94\u8be5\u4f7f\u7528\u53c2\u6570\u5316\u67e5\u8be2\u3002\u4e0b\u9762\u4f1a\u8be6\u7ec6\u8bf4\u660e<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">cur.execute()\u4e0e\u53c2\u6570<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u9996\u5148\u770b\u4e00\u773c\u539f\u578b\uff1a<code>def execute(self, query, args=None)<\/code><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u7b2c\u4e00\u4e2a\u53c2\u6570query\u4ee3\u8868\u8981\u6267\u884c\u7684SQL\u8bed\u53e5\uff0c\u7b2c\u4e8c\u4e2aargs\u4ee3\u8868\u53ef\u9009\u7684\u67e5\u8be2\u53c2\u6570\uff0c\u7c7b\u578b\u53ef\u4e3atuple, list or dict<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e5f\u5c31\u662f\u8bf4\uff0c\u6211\u4eec\u5e94\u8be5\u8fd9\u6837\u6267\u884cexecute\uff1a<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 12pt;\"><code>cur.execute('select version()')<\/code> \u4e0d\u9700\u8981\u4efb\u4f55\u53c2\u6570\uff0c\u76f4\u63a5\u4e00\u6574\u6761SQL\u8bed\u53e5\u3002<\/span><\/li>\n<li><span style=\"font-size: 12pt;\"><code>cur.execute('INSERT INTO sometable VALUES (%s,%s)', (1, 4))<\/code> \u53c2\u6570\u5316\u67e5\u8be2\uff0c%s\u662f\u5360\u4f4d\u7b26\uff0c\u4e0d\u9700\u8981\u8003\u8651\u5b57\u6bb5\u7c7b\u578b\u3002\u65e0\u8111%s\u6ca1\u4e8b\u7684\uff0c\u8fd9\u4e0d\u662fPython\u7684\u5b57\u7b26\u4e32%\u683c\u5f0f\u5316\u98ce\u683c\u8bed\u6cd5\u3002<\/span><\/li>\n<\/ol>\n<p><span style=\"font-size: 12pt;\">\u6839\u636e<a href=\"https:\/\/www.python.org\/dev\/peps\/pep-0249\/\">PEP 249<\/a>\uff0cclientlibrary.paramstyle\u53ef\u4ee5\u770b\u5230\u5360\u4f4d\u7b26\u98ce\u683c\uff0c\u6bd4\u5982\u8bf4\u81ea\u5e26\u7684sqlite3\u7684\u5360\u4f4d\u7b26\u5c31\u662f?\uff0cpymysql\u662fpyformat\uff0c\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u53ef\u4ee5<a href=\"https:\/\/stackoverflow.com\/questions\/7929364\/python-best-practice-and-securest-to-connect-to-mysql-and-execute-queries\">\u770b\u770b\u8fd9\u91cc<\/a><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6bd4\u8f83\u4e0d\u63a8\u8350\u7684\u6267\u884c\u67e5\u8be2\u7684\u65b9\u5f0f<\/span><\/p>\n<pre class=\"prettyprint linenums\">sql = &#039;insert into sometable values(&#039;\r\nsql = sql + &quot;&#039;&quot; + var1 + &quot;&#039;,&#039;&quot; + var2 + &quot;&#039;,&#039;&quot; + var3 + &quot;&#039;,&quot; + str(1984) + &quot;)&quot;\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u4ee5\u53ca\u4efb\u4f55\u82b1\u6837\u5faa\u73af\u62fc\u63a5\u7684\u65b9\u5f0f\uff0c\u770b\u7740\u90a3\u4e9b\u5355\u5f15\u53f7\u53cc\u5f15\u53f7\u6211\u90fd\u5934\u75bc\uff0c\u5c31\u7b97USE somedb\u8fd9\u79cd\u6ca1\u529e\u6cd5\u641e\u53c2\u6570\u5316\u67e5\u8be2\uff0c\u90a3\u54b1\u7528%s\u3001format\u3001f-string\u62fc\u5b57\u7b26\u4e32\u53ef\u8bfb\u6027\u4e5f\u6bd4\u8fd9\u79cd+\u7684\u597d\u3002\u51b5\u4e14+\u8981\u5f00\u8f9f\u65b0\u7684\u5185\u5b58\u7a7a\u95f4\uff0c\u4f1a\u66f4\u6162\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u63d0\u793a\uff1amysql connector\u7684cursor\u652f\u6301multiLine\u6a21\u5f0f\uff0c\u4e5f\u5c31\u662f\u8bf4\u53ef\u4ee5\u901a\u8fc7\u5206\u53f7\u6267\u884c\u591a\u6761SQL\u8bed\u53e5\u3002\u4e0d\u8fc7\uff0cpymysql\u4e0d\u652f\u6301\u54df\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">cur.executemany()\u53c2\u6570<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u4ee5\u4e3a\u4f1aexecute\u53c2\u6570\u5316\u67e5\u8be2\u5c31\u591f\u4e86\u5417\uff1f\u624d\u4e0d\u662f\u5462\uff0c\u8fdc\u8fdc\u8fd8\u4e0d\u591f\u3002\u6709\u4e9b\u65f6\u5019\u6211\u4eec\u9700\u8981\u5927\u91cf\u63d2\u5165\uff08\u6216\u662freplace\uff09\u3002\u6309\u7167\u4e00\u822c\u7684\u8111\u56de\u8def\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">sql = &quot;INSERT INTO sometable VALUES (%s,%s,%s)&quot;\r\nfor item in data:\r\n    cur.execute(sql, item)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u8fd8\u662f\u5148\u6765\u770b\u4e0bexecutemany\u7684\u539f\u578b\uff1a<code>executemany(self, query, args)<\/code><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u7b2c\u4e00\u4e2a\u53c2\u6570query\u8fd8\u662f\u5e26\u6709\u5360\u4f4d\u7b26\u7684SQL\u8bed\u53e5\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570args\u4e00\u822c\u6765\u8bf4\u662f\u53cc\u5c42\u5d4c\u5957\u7684\u53c2\u6570\u3002\u4f8b\u5b50\u5982\u4e0b\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">sql = &#039;INSERT INTO SOMETABLE VALUES (%s,%s,%s)&#039;\r\ndata = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\r\ncur.executemany(sql, data)\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u6838\u5fc3\u5173\u952e\u5c31\u5728\u8fd9\u91cc\uff0cexecutemany\u4f1a\u901a\u8fc7\u591a\u503c\u7684INSERT\u63d0\u5347\u6027\u80fd\uff0c\u5176\u4ed6\u60c5\u51b5\u4e0b\u5c31\u548c\u5faa\u73af\u8c03\u7528execute\u4e00\u6837\u4e86<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6709\u4e9b\u5c0f\u76c6\u53cb\u53ef\u80fd\u60f3\u95ee\uff0c\u4e3a\u5565executemany\u80fd\u591f\u63d0\u9ad8\u6027\u80fd\u5462\uff1f\u56e0\u4e3aexecutemany\u751f\u6210\u7684\u662f\u7c7b\u4f3c<code>INSERT INTO sometable VALUES(1,2,3),(4,5,6)<\/code>\u8fd9\u79cd\u8bed\u53e5\u554a\uff0c\u80af\u5b9a\u8981\u6bd4\u4e00\u6761\u4e00\u6761INSERT\u8981\u5feb\u5f88\u591a\u4e86\u3002\u4e0d\u8fc7\u4e3a\u4ec0\u4e48\u8bf4\u201c\u80af\u5b9a\u201d\u5462\uff1f\u60f3\u5f53\u7136\u662f\u5f88\u6b63\u5e38\u7684\uff0c\u6709\u7406\u6709\u636e\u7684\u60f3\u5f53\u7136\u624d\u662f\u53ef\u4ee5\u7684\uff08...( \uff3f \uff3f)\u30ce\uff5c\u7ee7\u7eed\u770b\u5c31\u77e5\u9053\u4e3a\u4ec0\u4e48\u4e86\uff09\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6ce8\u610f\uff0c\u7531\u4e8e\u5355\u6761SQL\u8bed\u53e5\u7684\u957f\u5ea6\u6709\u9650\u5236\uff0c\u8fd9\u91cc\u53ef\u80fd\u9700\u8981\u770b\u60c5\u51b5\u5206\u5272\u4e00\u4e0b\uff1a<\/span><\/p>\n<pre class=\"prettyprint linenums\">for i in range(0, len(data), SIZE):\r\n    part = data[i:i + SIZE]\r\n    # do something here, such as executemany\r\n<\/pre>\n<p><span style=\"font-size: 12pt;\">\u76f8\u4fe1\u6211\uff0c\u53ea\u8981\u63d2\u5165\u6570\u636e\u91cf\u8db3\u591f\u5927\uff0cexecutemany\u5c31\u80fd\u591f\u6210\u4e3a\u6027\u80fd\u63d0\u5347\u7684\u6700\u5173\u952e\u7684\u4e00\u70b9\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u54e6\u5bf9\u4e86\uff0cexecutemany\u914d\u5408\u53c2\u6570\u5316\u67e5\u8be2\u5df2\u7ecf\u5f88\u597d\u7528\u4e86\uff0c\u8fd8\u662f\u522b\u591a\u503cINSERT\uff0c\u867d\u8bf4\u4e5f\u80fd\u63d0\u9ad8\u6548\u7387\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4ee5\u4e0b\u6d4b\u8bd5\u6709\u4e00\u70b9\u9700\u8981\u6ce8\u610f\uff0c\u4e0d\u540c\u7684\u8868\u7ed3\u6784\u3001\u5b57\u6bb5\u7c7b\u578b\u6240\u5f97\u5230\u7684\u4e8c\u8005\u6bd4\u503c\u672a\u5fc5\u76f8\u540c\uff0c\u4f46\u603b\u4f53\u60c5\u51b5\u6beb\u65e0\u7591\u95ee\u662fexecutemany\u80dc\u51fa\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0b\u9762\u662f\u6211\u7684\u6d4b\u8bd5\uff0c\u6d4b\u8bd5\u811a\u672c\u53ef\u4ee5\u4ece\u5982\u4e0b\u5730\u5740\u83b7\u53d6\uff1a<br \/>\n<a class=\"dl\" href=\"https:\/\/github.com\/BennyThink\/tools\/tree\/master\/one_million\" target=\"_blank\" rel=\"nofollow\"><i class=\"fa fa-github-alt\"><\/i>\u5f00\u6e90\u5730\u5740<\/a><\/span><\/p>\n<table>\n<tbody>\n<tr>\n<td colspan=\"3\"><span style=\"font-size: 12pt;\">\u7b80\u5355\u8868\u7684\u6027\u80fdbenchmark<\/span><\/td>\n<\/tr>\n<tr>\n<td>\u63d2\u5165\u6761\u6570<\/td>\n<td><span style=\"font-size: 12pt;\">execute<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">executemany<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">1000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">0.35<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">0.02<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">5000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">0.84<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">0.06<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">10000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">4.16<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">0.34<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">20000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">4.87<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">0.39<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">50000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">19.43<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">0.93<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">100000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">40.84<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">3.18<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">500000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">165.72<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">9.76<\/span><\/td>\n<\/tr>\n<tr>\n<td><span style=\"font-size: 12pt;\">1000000<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">369.46<\/span><\/td>\n<td><span style=\"font-size: 12pt;\">29.43<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-size: 12pt;\"><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/11\/2018112701530413.png\" alt=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" title=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u770b\u4e00\u4e0b\u8fd9\u4e2a\u6298\u7ebf\u56fe\u66f4\u76f4\u89c2\u7684\u611f\u53d7\u4e0b\u5427\uff0c\u5e73\u5747\u6765\u8bf4executemany\u8981\u6bd4execute\u5feb\u4e0a\u81f3\u5c1110\u500d\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5176\u4ed6\u4e0d\u592a\u597d\u73a9\u65b9\u5f0f<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\"><strong>\u5173\u4e8e\u4e8b\u52a1\u4e0ecommit<\/strong><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0d\u8981\u5c1d\u8bd5\u82b1\u6837commit\uff0c\u6bd4\u5982\u8bf4\u4e00\u6761\u4e00\u6761\u63d2\uff0c\u6bcf\u63d2\u51651000\u6761commit\u4e00\u6b21\uff1b\u63d2\u4e00\u6761commit\u4e00\u6b21\u3002\u8fd9\u6bd4\u753b\u86c7\u6dfb\u8db3\u8fd8\u8fc7\u5206\uff0c\u8fd9\u5c31\u662f\u81ea\u8ba8\u82e6\u5403\u554a\u3002\u4e00\u8d77commit\u5c31\u5f97\u4e86\u3002\uff08\u5982\u679c\u6570\u636e\u53ef\u80fd\u4f1a\u63d2\u5165\u5931\u8d25\uff0c\u90a3\u4e48\u4e00\u5b9a\u8981\u7528try...except...finally\u63a7\u5236\u597d\u5f02\u5e38\u786e\u4fdd\u65e0\u8bef\uff09<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><strong>\u5e76\u53d1INSERT<\/strong><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5728\u4f7f\u7528InnoDB\u60c5\u51b5\u4e0b\uff0c\u7531\u4e8eInnoDB\u6709\u4e8b\u52a1\uff0c\u63d2\u5165\u65f6\u6709\u6392\u4ed6\u9501\uff0c\u8868\u7684\u7ed3\u6784\u53ef\u80fd\u4e0d\u540c\uff0c\u53ef\u80fd\u6709\u4e3b\u952e\u5916\u952e\u552f\u4e00\u7ea6\u675f\uff0c\u53ef\u80fd\u6709\u81ea\u589e\u975e\u7a7a\u9650\u5236\uff0c\u6570\u636e\u5e93\u7248\u672c\/\u914d\u7f6e\u53ef\u80fd\u4e0d\u540c\uff0c\u4e00\u4e9b\u5e93\u7684\u9650\u5236\uff0cGIL\u9501\u7b49\u7b49\uff0c\u8fd9\u4e2a\u53d8\u91cf\u5c31\u6709\u70b9\u592a\u5927\u4e86\u6709\u70b9\u96be\u63a7\u5236\u2026\u2026\u8fd9\u4e2a\u6211\u771f\u7684\u6ca1\u529e\u6cd5\u62ff\u6570\u636e\u8bf4\u8bdd\u3002<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5176\u4ed6\u5c0f\u7684\u4ee3\u7801\u56e0\u7d20<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u9664\u4e86execute\/executemany\u8fd9\u4e2a\u6700\u5927\u7684\u6027\u80fd\u56e0\u7d20\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0bPython\u5c42\u9762\u7684\u5bf9\u6027\u80fd\u63d0\u5347\u672a\u5fc5\u5f88\u660e\u663e\u7684\u5904\u7406\u65b9\u5f0f:<\/span><\/p>\n<ol>\n<li><span style=\"font-size: 12pt;\">\u62fc\u63a5\u5b57\u7b26\u4e32\uff1a\u5c3d\u91cf\u9009\u62e9f-string\u3001%\u3001format\u6216join\uff0c+\u662f\u6700\u6162\u7684\uff0c<a href=\"https:\/\/realpython.com\/python-f-strings\/#speed\" target=\"_blank\" rel=\"noopener noreferrer\">f-string\u662f\u6700\u5feb\u7684<\/a>\u3002<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">Python 2\u9700\u8981\u7279\u522b\u6ce8\u610f\u4e00\u4e9b\u65b9\u9762\uff0c\u6bd4\u5982range\u548cxrange\uff0cTrue\u548c1\u7b49<\/span><\/li>\n<\/ol>\n<h1><span style=\"font-size: 12pt;\">\u5176\u4ed6\u56e0\u7d20<\/span><\/h1>\n<h2><span style=\"font-size: 12pt;\">\u670d\u52a1\u5668\u6027\u80fd<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u5305\u542bMySQL\u7248\u672c\uff0c\u7f16\u8bd1\u4f18\u5316\uff0c\u5bbf\u4e3b\u673aIO\/CPU\/RAM\u7b49\u3002\u8fd9\u4e00\u70b9\u5c31\u5f88\u96be\u5c55\u5f00\u8bf4\u4e86\uff0c\u8bf4\u4e0d\u5b9a\u67d0\u4e2a\u7248\u672c\u7684MySQL\u5728\u67d0\u4e2a\u5e73\u53f0\u4e0a\u901a\u8fc7\u67d0\u4e2a\u7f16\u8bd1\u4f18\u5316\u53c2\u6570\u6027\u80fd\u5c31\u63d0\u5347\u4e8620%\u5462\u3002\u54e6\u5bf9\u4e86\uff0cPython\u5f00\u542f<code>--enable-optimizations<\/code>\u65f6\u636e\u8bf4\u6027\u80fd\u4f1a\u63d0\u534710%-20%\u5462\u3002<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u7f51\u7edc\u901f\u5ea6<\/span><\/h2>\n<p><span style=\"font-size: 12pt;\">\u5982\u679c\u662f\u8fdc\u7a0b\u8fde\u63a5\u5230\u6570\u636e\u5e93\u7684\u8bdd\uff0c\u90a3\u4e48\u51cf\u5c11\u8fde\u63a5\u6b21\u6570\u3001\u51cf\u5c11\u6570\u636e\u91cf\u662f\u66f4\u52a0\u7684\u9009\u62e9\uff0c\u6b64\u65f6\u5c31\u66f4\u5e94\u8be5\u9009\u62e9\u6279\u91cf\u7684executemany\u800c\u4e0d\u662fexecute\u4e86\u3002\u56e0\u4e3a\u591a\u6b21execute\u4f1a\u55f7\u55f7\u7684\u589e\u52a0\u4e0a\u4f20\u548c\u4e0b\u8f7d\u7684\u6d41\u91cf\uff0c\u800cexecutemany\u4e0d\u4f1a\u589e\u52a0\u4e0b\u8f7d\u7684\u6d41\u91cf\uff0c\u5c31\u8fde\u4e0a\u4f20\u6d41\u91cf\u7684\u589e\u52a0\u4e5f\u4e0d\u90a3\u4e48\u53ef\u6015\u54df\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u8fd8\u597d\u90fd\u662f\u4e00\u4e2aTCP\u8fde\u63a5\u91cc\u8d70\u7684\uff0c\u8981\u4e0d\u5c31\u66f4\u60e8\u4e0d\u5fcd\u7779\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0d\u4fe1\u6211\u6293\u5305\u7ed9\u4f60\u770b~<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u5355\u4e2aexecute<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\"><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/11\/20181127015305100.png\" alt=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" title=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e00\u5171\u8fd9\u4e48\u51e0\u4e2a\u8bf7\u6c42\uff0c\u4e00\u4e2aautocommit=0\uff0c\u4e00\u4e2acommit\uff0c\u4e09\u4e2a\u67e5\u8be2\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/11\/2018112701530643.png\" alt=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" title=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u534f\u8bae\u7edf\u8ba1\u544a\u8bc9\u6211\u4eec\uff0c\u6211\u53d1\u9001\u4e86682\u5b57\u8282\uff0c\u63a5\u53d7\u4e86628\u5b57\u8282\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4e0b\u9762\u6211\u4eec\u6765\u770b\u4e0bexecutemany<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">executemany<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\"><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/11\/2018112701530642.png\" alt=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" title=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u4ece\u56fe\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u5230\uff0c\u4e00\u4e2aautocommit=0\uff0c\u4e00\u4e2acommit\uff0c\u5916\u52a0\u4e00\u6b21\u67e5\u8be2\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/11\/2018112701530789.png\" alt=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" title=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u534f\u8bae\u7edf\u8ba1\u544a\u8bc9\u6211\u4eec\uff0c\u53d1\u9001\u4e86514\u5b57\u8282\uff0c\u63a5\u6536\u4e86537\u5b57\u8282\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5047\u5982\u6211\u628a\u6570\u636e\u91cf\u4ece3\u6539\u62101000\uff0c\u90a3\u4e48\u2026\u2026<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/11\/2018112701530770.png\" alt=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" title=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u5355\u6b21execute\u53d1\u900194K\u63a5\u53d765K<\/span><\/p>\n<p><span style=\"font-size: 12pt;\"><img decoding=\"async\" src=\"https:\/\/7bc5d24.webp.ee\/wp-content\/uploads\/2018\/11\/2018112701530850.png\" alt=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" title=\"\u5047\u5982\u7ed9\u6211\u4e00\u767e\u4e07\uff08\u7684\u6570\u636e\uff09\" \/><\/span><\/p>\n<p><span style=\"font-size: 12pt;\">Executemany\u53d1\u900110K\u63a5\u53d7542\u5b57\u8282<\/span><\/p>\n<h3><span style=\"font-size: 12pt;\">\u7f51\u901f\u5f71\u54cd\u603b\u7ed3<\/span><\/h3>\n<p><span style=\"font-size: 12pt;\">\u7efc\u4e0a\uff0c\u5728\u6570\u91cf\u7ea7\u4e3a1000\u7684\u60c5\u51b5\u4e0b\uff0cexecute\u603b\u6d41\u91cf\u662f159K\uff0cexecutemany\u662f10.53K\uff0c\u5dee\u4e86\u63a5\u8fd115\u500d\u3002\u90a3\u4e48\u5728\u4f4e\u7f51\u901f\u3001\u5927\u6570\u636e\u7684\u60c5\u51b5\u4e0b\u8c01\u7684\u4f18\u52bf\u66f4\u660e\u663e\u5c31\u4e0d\u8a00\u800c\u55bb\u4e86\u3002<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u5047\u5982\u5355\u72ecexecutemany\u7684\u65f6\u5019\u5dee\u4e86\u5341\u500d\uff0c\u6d41\u91cf\u53c8\u5dee\u4e86\u5341\u500d\uff0c\u90a3\u662f\u4e0d\u662f\u4e00\u5171\u5c31\u5dee\u4e86100\u500d\u4e86\uff1f<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">(\u3000o=^\u2022\u30a7\u2022)o\u3000\u250f\u2501\u2513\uff08\u4f60\u770b\u684c\u5b50\u90fd\u7ffb\u4e86\uff0c\u6240\u4ee5\u5462\uff09\u4e0d\u53ef\u4ee5\u8fd9\u4e48\u8ba1\u7b97\u7684\uff0c\u5927\u90e8\u5206\u60c5\u51b5\u4e0b\u7f51\u901f\u5bf9\u6027\u80fd\u7684\u5f71\u54cd\u5e76\u4e0d\u662f\u90a3\u4e48\u660e\u663e\uff0c\u5f53\u7f51\u901f\u8db3\u591f\u6162\u3001\u6570\u636e\u8db3\u591f\u5927\u65f6\uff0c\u8fd9\u4e2a\u5f71\u54cd\u5c31\u4f1a\u88ab\u653e\u5927\uff1b\u53cd\u4e4b\u8fd9\u4e2a\u5f71\u54cd\u53ef\u4ee5\u5ffd\u7565\u4e0d\u8ba1\u3002\u6240\u4ee5\u6b63\u786e\u8ba1\u7b97\u662f\u8981\u52a0\u6743\u91cd\u7684\uff0c\u7136\u800c\u8fd9\u4e2a\u6743\u91cd\u662f\u51e0\u4e4e\u65e0\u6cd5\u5f97\u5230\u7684\u03b5=\u03b5=\u03b5=\u250f(\u309c\u30ed\u309c;)\u251b<\/span><\/p>\n<p><span style=\"font-size: 12pt;\">\u6240\u4ee5\uff0c\u5982\u679c\u5728\u8fdc\u7a0b\u8fde\u63a5\u6570\u636e\u5e93\u7684\u60c5\u51b5\u4e0b\u6267\u884c\u67e5\u8be2\uff0c\u90a3\u4e48\u6570\u636e\u91cf\u5927\u7684\u65f6\u5019\uff0c\u56e0\u4e3a\u5355\u6b21execute\u5bfc\u81f4\u4e86\u7f51\u7edc\u4f20\u8f93\u91cf\u7684\u6025\u5267\u4e0a\u5347\uff0cexecute\u7684\u8d1f\u9762\u6548\u5e94\u4f1a\u88ab\u4e00\u5b9a\u7a0b\u5ea6\u7684\u653e\u5927\u3002<\/span><\/p>\n<h2><span style=\"font-size: 12pt;\">\u6700\u7ec8\u7684\u603b\u7ed3<\/span><\/h2>\n<ol>\n<li><span style=\"font-size: 12pt;\">\u5b98\u65b9\u6587\u6863\u662f\u7b2c\u4e8c\u597d\u7684\u53c2\u8003\u6765\u6e90\uff0c\u90a3\u4e48\u7b2c\u4e00\u597d\u7684\u53c2\u8003\u6765\u6e90\u662f\u4ec0\u4e48\uff1f\u6e90\u4ee3\u7801\u5566\uff1b<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">\u5f53\u9047\u5230\u95ee\u9898\u7684\u65f6\u5019\uff0c\u60f3\u5f53\u7136\u662f\u5f88\u6b63\u5e38\u7684\uff0c\u4f46\u662f\u66f4\u91cd\u8981\u7684\u662f\u901a\u8fc7\u5206\u6790\u5b9e\u9a8c\u4e0e\u6570\u636e\u4e86\u89e3\u5e76\u8bc1\u5b9e\u731c\u60f3\uff1b<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">\u67d0\u4e9b\u56e0\u7d20\u53ef\u80fd\u4f1a\u4e92\u76f8\u5f71\u54cd\u3002\u50cf\u672c\u4f8bexecute\u7684\u526f\u4f5c\u7528\u4e4b\u4e00\u5c31\u662f\u4f1a\u589e\u52a0\u7f51\u7edc\u6d41\u91cf\uff0c\u6240\u4ee5execute\u624d\u662f\u6839\u6e90\uff0c\u7f51\u901f\u53ea\u662f\u4f34\u968f\u7684\u526f\u4f5c\u7528\u800c\u5df2\uff0c\u4e0d\u53ef\u56e0\u679c\u5012\u7f6e\uff1b<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">\u67d0\u4e9b\u6027\u80fd\u56e0\u7d20\u662f\u5f88\u96be\u63a7\u5236\u7684\uff0c\u6bd4\u5982\u670d\u52a1\u5668CPU\/RAM\/IO\uff0cPython\u89e3\u91ca\u5668\u6027\u80fd\uff0cMySQL\u7248\u672c\/\u7f16\u8bd1\u9009\u9879\/\u914d\u7f6e\/\u96c6\u7fa4\uff0c\u751a\u81f3\u662f\u64cd\u4f5c\u7cfb\u7edf\u3001\u5185\u6838\u7684\u5dee\u8ddd\u3002\u8fd9\u79cd\u56e0\u7d20\u7684\u53d8\u91cf\u51e0\u4e4e\u5f88\u96be\u63a7\u5236\uff0c\u90a3\u4e48\u5c31\u4e0d\u8981\u8003\u8651\u4e86\uff0c\u7b49\u67d0\u56e0\u7d20\u6210\u4e3a\u5173\u952e\u70b9\u7684\u65f6\u5019\u518d\u53bb\u5206\u6790\uff1b<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">\u6211\u6709\u4ee3\u7801\u6d01\u7656\uff1b<\/span><\/li>\n<li><span style=\"font-size: 12pt;\">\u8fd9\u53ef\u80fd\u662f\u4e00\u4e2a\u706b\u82d7<\/span><\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u7bc7\u6587\u7ae0\u5728 2019\u5e7403\u670801\u65e516:39:35 \u66f4\u65b0\u4e86\u54e6~\u5f88\u957f\u65f6\u95f4\u4e4b\u524d\u6211\u5199\u8fc7\u4e00\u7bc7\u300a\u4f7f\u7528 Python \u5c06\u6d77 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[38],"tags":[],"class_list":["post-3915","post","type-post","status-publish","format-standard","hentry","category-program"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/3915","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/comments?post=3915"}],"version-history":[{"count":0,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/posts\/3915\/revisions"}],"wp:attachment":[{"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/media?parent=3915"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/categories?post=3915"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dmesg.app\/wp-json\/wp\/v2\/tags?post=3915"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}