{"id":62,"date":"2024-12-04T04:05:00","date_gmt":"2024-12-04T04:05:00","guid":{"rendered":"http:\/\/211.230.203.47\/wordpress\/?p=62"},"modified":"2024-12-04T04:05:00","modified_gmt":"2024-12-04T04:05:00","slug":"%ed%8c%8c%ec%9d%b4%ec%85%98%ec%9c%bc%eb%a1%9c-%ec%9b%b9%ed%94%84%eb%a1%9c%ea%b7%b8%eb%9e%a8%ec%9d%84-%eb%a7%8c%eb%93%a4%eb%95%8c-mysql-%ec%84%9c%eb%b2%84%ec%99%80-%ec%97%b0%ea%b2%b0%ed%95%98%eb%8a%94","status":"publish","type":"post","link":"https:\/\/www.soon7shop.kr\/wordpress\/?p=62","title":{"rendered":"\ud30c\uc774\uc158\uc73c\ub85c \uc6f9\ud504\ub85c\uadf8\ub7a8\uc744 \ub9cc\ub4e4\ub54c mysql \uc11c\ubc84\uc640 \uc5f0\uacb0\ud558\ub294 \ubc29\ubc95"},"content":{"rendered":"<p>Python\uc73c\ub85c \uc6f9 \ud504\ub85c\uadf8\ub7a8\uc744 \ub9cc\ub4e4 \ub54c MySQL \uc11c\ubc84\uc640 \uc5f0\uacb0\ud558\ub294 \uc77c\ubc18\uc801\uc778 \ubc29\ubc95\uc740 <code>mysql-connector-python<\/code>\uacfc \uac19\uc740 MySQL \ucee4\ub125\ud130 \ub77c\uc774\ube0c\ub7ec\ub9ac\ub97c \uc0ac\uc6a9\ud558\ub294 \uac83\uc785\ub2c8\ub2e4. \uc5ec\uae30\uc11c\ub294 Python Flask \uc6f9 \ud504\ub808\uc784\uc6cc\ud06c\uc640 MySQL \ub370\uc774\ud130\ubca0\uc774\uc2a4\ub97c \uc5f0\uacb0\ud558\uc5ec \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95\uc744 \uc548\ub0b4\ub4dc\ub9b4\uac8c\uc694.<\/p>\n<h3>1. \ub77c\uc774\ube0c\ub7ec\ub9ac \uc124\uce58<\/h3>\n<p>\uba3c\uc800, <code>mysql-connector-python<\/code> \ud328\ud0a4\uc9c0\ub97c \uc124\uce58\ud574\uc57c \ud569\ub2c8\ub2e4.<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">pip install mysql-connector-python Flask<br \/>\n<\/code><\/div>\n<\/div>\n<h3>2. MySQL \ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc124\uc815<\/h3>\n<p>MySQL\uc5d0\uc11c \uc0ac\uc6a9\ud560 \ub370\uc774\ud130\ubca0\uc774\uc2a4\uc640 \ud14c\uc774\ube14\uc744 \uc124\uc815\ud569\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, <code>mydatabase<\/code>\ub77c\ub294 \ub370\uc774\ud130\ubca0\uc774\uc2a4\uc640 <code>users<\/code>\ub77c\ub294 \ud14c\uc774\ube14\uc744 \ub9cc\ub4e4\uace0 \uc2f6\ub2e4\uba74 \ub2e4\uc74c\uacfc \uac19\uc774 \uc124\uc815\ud569\ub2c8\ub2e4:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none\">sql<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-sql\"><span class=\"hljs-keyword\">CREATE<\/span> DATABASE mydatabase;<br \/>\nUSE mydatabase;<\/p>\n<p><span class=\"hljs-keyword\">CREATE<\/span> <span class=\"hljs-keyword\">TABLE<\/span> users (<br \/>\n    id <span class=\"hljs-type\">INT<\/span> AUTO_INCREMENT <span class=\"hljs-keyword\">PRIMARY<\/span> KEY,<br \/>\n    name <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>),<br \/>\n    email <span class=\"hljs-type\">VARCHAR<\/span>(<span class=\"hljs-number\">100<\/span>)<br \/>\n);<br \/>\n<\/code><\/div>\n<\/div>\n<h3>3. Python\uc5d0\uc11c MySQL \uc5f0\uacb0 \uc124\uc815<\/h3>\n<p>Flask \uc560\ud50c\ub9ac\ucf00\uc774\uc158 \ud30c\uc77c\uc744 \uc0dd\uc131\ud558\uace0 MySQL \ub370\uc774\ud130\ubca0\uc774\uc2a4\uc5d0 \uc5f0\uacb0\ud574\ubcf4\uaca0\uc2b5\ub2c8\ub2e4.<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none\">python<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\"><\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code>from flask import Flask, request, jsonify<br \/>\nimport mysql.connector<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code>app = Flask(__name__)<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code># MySQL \uc5f0\uacb0 \uc124\uc815<br \/>\ndb = mysql.connector.connect(<br \/>\nhost=&#8221;localhost&#8221;, # MySQL \uc11c\ubc84 \ud638\uc2a4\ud2b8<br \/>\nuser=&#8221;root&#8221;, # MySQL \uc0ac\uc6a9\uc790<br \/>\npassword=&#8221;password&#8221;, # MySQL \ube44\ubc00\ubc88\ud638<br \/>\ndatabase=&#8221;mydatabase&#8221; # \uc5f0\uacb0\ud560 \ub370\uc774\ud130\ubca0\uc774\uc2a4<br \/>\n)<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code># \ub370\uc774\ud130 \ucd94\uac00 API \uc608\uc81c<br \/>\n@app.route(&#8216;\/add_user&#8217;, methods=[&#8216;POST&#8217;])<br \/>\ndef add_user():<br \/>\ndata = request.json<br \/>\nname = data.get(&#8216;name&#8217;)<br \/>\nemail = data.get(&#8217;email&#8217;)<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code>cursor = db.cursor()<br \/>\nquery = &#8220;INSERT INTO users (name, email) VALUES (%s, %s)&#8221;<br \/>\nvalues = (name, email)<br \/>\ncursor.execute(query, values)<br \/>\ndb.commit()<\/p>\n<p>return jsonify({&#8220;message&#8221;: &#8220;User added successfully!&#8221;})<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code># \ubaa8\ub4e0 \ub370\uc774\ud130 \uc870\ud68c API \uc608\uc81c<br \/>\n@app.route(&#8216;\/users&#8217;, methods=[&#8216;GET&#8217;])<br \/>\ndef get_users():<br \/>\ncursor = db.cursor(dictionary=True)<br \/>\ncursor.execute(&#8220;SELECT * FROM users&#8221;)<br \/>\nusers = cursor.fetchall()<\/p>\n<p>return jsonify(users)<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><code class=\"!whitespace-pre hljs language-python\"><\/code><\/code>if __name__ == &#8216;__main__&#8217;:<br \/>\napp.run(debug=True)<\/p>\n<p><code class=\"!whitespace-pre hljs language-python\"><br \/>\n<\/code><\/div>\n<\/div>\n<h3>4. \uc2e4\ud589 \ubc0f \ud14c\uc2a4\ud2b8<\/h3>\n<p>\uc774\uc81c \uc11c\ubc84\ub97c \uc2e4\ud589\ud558\uace0 \ud14c\uc2a4\ud2b8\ud574\ubcf4\uc138\uc694:<\/p>\n<div class=\"contain-inline-size rounded-md border-[0.5px] border-token-border-medium relative bg-token-sidebar-surface-primary dark:bg-gray-950\">\n<div class=\"flex items-center text-token-text-secondary px-4 py-2 text-xs font-sans justify-between rounded-t-md h-9 bg-token-sidebar-surface-primary dark:bg-token-main-surface-secondary select-none\">bash<\/div>\n<div class=\"sticky top-9 md:top-[5.75rem]\">\n<div class=\"absolute bottom-0 right-2 flex h-9 items-center\">\n<div class=\"flex items-center rounded bg-token-sidebar-surface-primary px-2 font-sans text-xs text-token-text-secondary dark:bg-token-main-surface-secondary\"><\/div>\n<\/div>\n<\/div>\n<div class=\"overflow-y-auto p-4\" dir=\"ltr\"><code class=\"!whitespace-pre hljs language-bash\">python app.py<br \/>\n<\/code><\/div>\n<\/div>\n<p><code>http:\/\/localhost:5000\/add_user<\/code>\uc5d0 POST \uc694\uccad\uc744 \ubcf4\ub0b4\uc11c \uc0ac\uc6a9\uc790 \uc815\ubcf4\ub97c \ucd94\uac00\ud558\uac70\ub098, <code>http:\/\/localhost:5000\/users<\/code>\ub85c GET \uc694\uccad\uc744 \ubcf4\ub0b4\uc11c \uc800\uc7a5\ub41c \uc0ac\uc6a9\uc790 \uc815\ubcf4\ub97c \uc870\ud68c\ud560 \uc218 \uc788\uc2b5\ub2c8\ub2e4.<\/p>\n<p>\uc774 \uacfc\uc815\uc774 MySQL\uacfc \uc5f0\uacb0\ud558\uc5ec \ub370\uc774\ud130\ub97c \ucc98\ub9ac\ud558\ub294 \uae30\ubcf8\uc801\uc778 \uc6f9 \ud504\ub85c\uadf8\ub7a8 \uad6c\ucd95 \uacfc\uc815\uc785\ub2c8\ub2e4.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Python\uc73c\ub85c \uc6f9 \ud504\ub85c\uadf8\ub7a8\uc744 \ub9cc\ub4e4 \ub54c MySQL \uc11c\ubc84\uc640 \uc5f0\uacb0\ud558\ub294 \uc77c\ubc18\uc801\uc778 \ubc29\ubc95\uc740 mysql-connector-python\uacfc \uac19\uc740 MySQL \ucee4\ub125\ud130 \ub77c\uc774\ube0c\ub7ec\ub9ac\ub97c \uc0ac\uc6a9\ud558\ub294 \uac83\uc785\ub2c8\ub2e4. \uc5ec\uae30\uc11c\ub294 Python Flask \uc6f9 \ud504\ub808\uc784\uc6cc\ud06c\uc640 MySQL \ub370\uc774\ud130\ubca0\uc774\uc2a4\ub97c \uc5f0\uacb0\ud558\uc5ec \uc0ac\uc6a9\ud558\ub294 \ubc29\ubc95\uc744 \uc548\ub0b4\ub4dc\ub9b4\uac8c\uc694. 1. \ub77c\uc774\ube0c\ub7ec\ub9ac \uc124\uce58 \uba3c\uc800, mysql-connector-python \ud328\ud0a4\uc9c0\ub97c \uc124\uce58\ud574\uc57c \ud569\ub2c8\ub2e4. bash pip install mysql-connector-python Flask 2. MySQL \ub370\uc774\ud130\ubca0\uc774\uc2a4 \uc124\uc815 MySQL\uc5d0\uc11c \uc0ac\uc6a9\ud560 \ub370\uc774\ud130\ubca0\uc774\uc2a4\uc640 \ud14c\uc774\ube14\uc744 \uc124\uc815\ud569\ub2c8\ub2e4. \uc608\ub97c \ub4e4\uc5b4, mydatabase\ub77c\ub294 \ub370\uc774\ud130\ubca0\uc774\uc2a4\uc640 users\ub77c\ub294 &hellip; <a href=\"https:\/\/www.soon7shop.kr\/wordpress\/?p=62\" class=\"more-link\">\ub354 \ubcf4\uae30<span class=\"screen-reader-text\"> &#8220;\ud30c\uc774\uc158\uc73c\ub85c \uc6f9\ud504\ub85c\uadf8\ub7a8\uc744 \ub9cc\ub4e4\ub54c mysql \uc11c\ubc84\uc640 \uc5f0\uacb0\ud558\ub294 \ubc29\ubc95&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-62","post","type-post","status-publish","format-standard","hentry","category-6"],"_links":{"self":[{"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/62","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=62"}],"version-history":[{"count":1,"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/62\/revisions"}],"predecessor-version":[{"id":63,"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/62\/revisions\/63"}],"wp:attachment":[{"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=62"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=62"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.soon7shop.kr\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=62"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}