{"id":304738,"date":"2020-06-02T21:00:28","date_gmt":"2020-06-02T21:00:28","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=304738"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=304738","title":{"rendered":"\u0412\u0441\u0442\u0430\u0432\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 numpy \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL \u0447\u0435\u0440\u0435\u0437 Python"},"content":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/505060\/\">\u0415\u0441\u043b\u0438 \u0412\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0447\u0442\u043e <b>\u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 numpy \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL<\/b>, \u0442\u043e \u044d\u0442\u0430 \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u0434\u043b\u044f \u0412\u0430\u0441! \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u043f\u043e\u0441\u0442\u0430 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d \u0432 <a href=\"https:\/\/www.alexanyan.tech\/\" rel=\"nofollow\">\u043c\u043e\u0435\u043c \u0431\u043b\u043e\u0433\u0435<\/a>. <\/p>\n<p>  \u042f \u0432\u044b\u0431\u0440\u0430\u043b \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0443\u043b\u044c <b>pickle<\/b>. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e \u0412\u044b \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 numpy \u043b\u044e\u0431\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0432 blob-\u0435 \u0431\u0430\u0437\u044b MySQL. <br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a, \u043f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430: <\/p>\n<pre><code class=\"python\">import mysql.connector import pickle import numpy as np  #\u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043a \u043d\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 connection = mysql.connector.connect(host='localhost',                                          database='database',                                          user='root',                                          password='') #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440 cursor = connection.cursor()  #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0442\u0435\u0441\u0442 \u0441 \u043e\u0434\u043d\u0438\u043c \u043f\u043e\u043b\u0435\u043c \u0442\u0438\u043f\u0430 blob query = 'create table test(`column` blob);' cursor.execute(query)  #\u0421\u043e\u0437\u0434\u0430\u0435\u043c \u043c\u0430\u0441\u0441\u0438\u0432 numpy  array = np.array([[1,2,3],[4,5,6]])  #\u0412\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0430\u0448 \u043c\u0430\u0441\u0441\u0438\u0432 \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u0435 pickle.dumps query = 'insert into test values(%s);' db_array = pickle.dumps(array) cursor.execute(query, [db_array ])  #\u041e\u0442\u0431\u0438\u0440\u0430\u0435\u043c \u0432\u0441\u0435 \u0441\u0442\u0440\u043e\u043a\u0438 \u0438\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b test query = 'select * from test;' cursor.execute(query) res = cursor.fetchall()  #\u0421\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 res  ##\u041f\u043e\u043b\u0443\u0447\u0438\u043b\u0438 \u0432\u043e\u0442 \u0442\u0430\u043a\u0443\u044e \u0432\u0435\u0449\u044c: [(bytearray(b'\\x80\\x03cnumpy.core.multiarray\\n_reconstruct\\nq\\x00cnumpy\\nndarray\\nq\\x01K\\x00\\x85q\\x02C\\x01bq\\x03\\x87q\\x04Rq\\x05(K\\x01K\\x02K\\x03\\x86q\\x06cnumpy\\ndtype\\nq\\x07X\\x02\\x00\\x00\\x00i8q\\x08K\\x00K\\x01\\x87q\\tRq\\n(K\\x03X\\x01\\x00\\x00\\x00&lt;q\\x0bNNNJ\\xff\\xff\\xff\\xffJ\\xff\\xff\\xff\\xffK\\x00tq\\x0cb\\x89C0\\x01\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x02\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x03\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x04\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x05\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x06\\x00\\x00\\x00\\x00\\x00\\x00\\x00q\\rtq\\x0eb.'),)]  #\u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e pickle.load \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u0443\u0435\u043c \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 numpy pickle.loads(res[0][0])  ##\u0412\u043e\u0442 \u0447\u0442\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c array([[1, 2, 3],        [4, 5, 6]])  #\u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u043c \u043a\u0443\u0440\u0441\u043e\u0440 \u0438 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u043a \u0411\u0414               cursor.close() connection.close()<\/code><\/pre>\n<p>  \u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u0412\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0430\u0431\u0441\u043e\u043b\u044e\u0442\u043d\u043e \u0431\u0435\u0441\u043f\u0440\u0435\u043f\u044f\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0431\u043c\u0435\u043d\u0438\u0432\u0430\u0442\u044c\u0441\u044f \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u043c\u0438 (\u0438 \u043e\u0431\u044b\u0447\u043d\u044b\u043c\u0438) \u043c\u0430\u0441\u0441\u0438\u0432\u0430\u043c\u0438 numpy \u043c\u0435\u0436\u0434\u0443 Python \u0438 MySQL. \u0415\u0441\u043b\u0438 \u0412\u044b \u043f\u0440\u043e\u0447\u0438\u0442\u0430\u043b\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e cv2.imread \u0438\u0437 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 OpenCV, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f \u043e\u0441\u0442\u0430\u0435\u0442\u0441\u044f \u0442\u0435\u043c \u0436\u0435 \u2014 \u0432\u0435\u0434\u044c \u044d\u0442\u043e, \u043f\u043e \u0441\u0443\u0442\u0438, \u043c\u043d\u043e\u0433\u043e\u043c\u0435\u0440\u043d\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432. <\/p>\n<p>  \u041d\u0430\u0434\u0435\u044e\u0441\u044c, \u043a\u043e\u043c\u0443-\u0442\u043e \u044d\u0442\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438 \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u0439 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b!<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/post\/505060\/\"> https:\/\/habr.com\/ru\/post\/505060\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"\n<div class=\"post__text post__text-html post__text_v1\" id=\"post-content-body\" data-io-article-url=\"https:\/\/habr.com\/ru\/post\/505060\/\">\u0415\u0441\u043b\u0438 \u0412\u044b \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0438\u0441\u044c \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439, \u0447\u0442\u043e <b>\u043d\u0435 \u043c\u043e\u0436\u0435\u0442\u0435 \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043c\u0430\u0441\u0441\u0438\u0432 numpy \u0432 \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 MySQL<\/b>, \u0442\u043e \u044d\u0442\u0430 \u0437\u0430\u043c\u0435\u0442\u043a\u0430 \u0434\u043b\u044f \u0412\u0430\u0441! \u041e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u043f\u043e\u0441\u0442\u0430 \u043e\u043f\u0443\u0431\u043b\u0438\u043a\u043e\u0432\u0430\u043d \u0432 <a href=\"https:\/\/www.alexanyan.tech\/\" rel=\"nofollow\">\u043c\u043e\u0435\u043c \u0431\u043b\u043e\u0433\u0435<\/a>. <\/p>\n<p>  \u042f \u0432\u044b\u0431\u0440\u0430\u043b \u0434\u043b\u044f \u0441\u0435\u0431\u044f \u0441\u043f\u043e\u0441\u043e\u0431 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0447\u0435\u0440\u0435\u0437 \u043c\u043e\u0434\u0443\u043b\u044c <b>pickle<\/b>. \u0421 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043d\u0435\u0433\u043e \u0412\u044b \u0441\u043f\u043e\u043a\u043e\u0439\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u0442\u0435 \u043c\u0430\u0441\u0441\u0438\u0432 numpy \u043b\u044e\u0431\u043e\u0439 \u0440\u0430\u0437\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u0438 \u0432 blob-\u0435 \u0431\u0430\u0437\u044b MySQL.   <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-304738","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304738","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=304738"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/304738\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=304738"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=304738"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=304738"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}