{"id":195,"date":"2024-12-17T20:52:12","date_gmt":"2024-12-17T12:52:12","guid":{"rendered":"http:\/\/trantor.ink:8080\/?p=195"},"modified":"2024-12-25T14:18:42","modified_gmt":"2024-12-25T06:18:42","slug":"mysql-%e6%9f%a5%e7%9c%8b%e7%94%a8%e6%88%b7","status":"publish","type":"post","link":"https:\/\/trantor.ink\/?p=195","title":{"rendered":"mysql \u67e5\u770b\u7528\u6237"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/trantor.ink\/?p=195\/#1_%E7%99%BB%E5%BD%95%E5%88%B0_MySQL\" >1. \u767b\u5f55\u5230 MySQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/trantor.ink\/?p=195\/#2_%E5%88%87%E6%8D%A2%E5%88%B0_mysql_%E6%95%B0%E6%8D%AE%E5%BA%93\" >2. \u5207\u6362\u5230 mysql \u6570\u636e\u5e93<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/trantor.ink\/?p=195\/#3_%E6%9F%A5%E8%AF%A2%E7%94%A8%E6%88%B7%E5%88%97%E8%A1%A8\" >3. \u67e5\u8be2\u7528\u6237\u5217\u8868<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/trantor.ink\/?p=195\/#4_%E9%80%80%E5%87%BA_MySQL\" >4. \u9000\u51fa MySQL<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/trantor.ink\/?p=195\/#%E8%A7%A3%E9%87%8A%E7%BB%93%E6%9E%9C\" >\u89e3\u91ca\u7ed3\u679c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/trantor.ink\/?p=195\/#%E7%A4%BA%E4%BE%8B\" >\u793a\u4f8b<\/a><\/li><\/ul><\/nav><\/div>\n\n<p>\u5728 MySQL \u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u6765\u67e5\u770b\u6570\u636e\u5e93\u4e2d\u6240\u6709\u7528\u6237\u7684\u5217\u8868\uff1a<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_%E7%99%BB%E5%BD%95%E5%88%B0_MySQL\"><\/span>1. \u767b\u5f55\u5230 MySQL<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u9996\u5148\uff0c\u4f60\u9700\u8981\u767b\u5f55\u5230 MySQL \u6570\u636e\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">mysql -u root -p<\/pre>\n\n\n\n<p>\u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u8f93\u5165 root \u7528\u6237\u7684\u5bc6\u7801\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_%E5%88%87%E6%8D%A2%E5%88%B0_mysql_%E6%95%B0%E6%8D%AE%E5%BA%93\"><\/span>2. \u5207\u6362\u5230 <code>mysql<\/code> \u6570\u636e\u5e93<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>MySQL \u7684\u7528\u6237\u4fe1\u606f\u5b58\u50a8\u5728 <code>mysql<\/code> \u6570\u636e\u5e93\u4e2d\u7684 <code>user<\/code> \u8868\u4e2d\u3002\u4f60\u9700\u8981\u5207\u6362\u5230\u8be5\u6570\u636e\u5e93\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">USE mysql;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_%E6%9F%A5%E8%AF%A2%E7%94%A8%E6%88%B7%E5%88%97%E8%A1%A8\"><\/span>3. \u67e5\u8be2\u7528\u6237\u5217\u8868<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u8fd0\u884c\u4ee5\u4e0b SQL \u8bed\u53e5\u6765\u67e5\u770b\u6240\u6709\u7528\u6237\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">SELECT User, Host FROM user;<\/pre>\n\n\n\n<p>\u8fd9\u5c06\u663e\u793a\u6240\u6709\u7528\u6237\u4ee5\u53ca\u4ed6\u4eec\u5bf9\u5e94\u7684\u4e3b\u673a\uff08Host\uff09\u3002\u7528\u6237\u7684\u540d\u79f0\u5217\u5728 <code>User<\/code> \u5217\u4e2d\uff0c\u800c <code>Host<\/code> \u5217\u8868\u793a\u7528\u6237\u53ef\u4ee5\u4ece\u54ea\u4e2a\u4e3b\u673a\u8fde\u63a5\u5230 MySQL\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_%E9%80%80%E5%87%BA_MySQL\"><\/span>4. \u9000\u51fa MySQL<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u67e5\u770b\u5b8c\u7528\u6237\u5217\u8868\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa MySQL \u63a7\u5236\u53f0\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">exit;<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E8%A7%A3%E9%87%8A%E7%BB%93%E6%9E%9C\"><\/span>\u89e3\u91ca\u7ed3\u679c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>User<\/strong>: \u8fd9\u4e2a\u5b57\u6bb5\u663e\u793a\u7528\u6237\u540d\u3002<\/li>\n\n\n\n<li><strong>Host<\/strong>: \u8fd9\u4e2a\u5b57\u6bb5\u663e\u793a\u7528\u6237\u53ef\u4ee5\u4ece\u54ea\u4e2a\u4e3b\u673a\u767b\u5f55\u3002\u5982\u679c\u662f <code>'%'<\/code>\uff0c\u8868\u793a\u8be5\u7528\u6237\u53ef\u4ee5\u4ece\u4efb\u4f55\u4e3b\u673a\u767b\u5f55\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"%E7%A4%BA%E4%BE%8B\"><\/span>\u793a\u4f8b<span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>\u5047\u8bbe\u4f60\u8fd0\u884c\u4e86\u4e0a\u9762\u7684 <code>SELECT<\/code> \u8bed\u53e5\uff0c\u4f60\u53ef\u80fd\u4f1a\u770b\u5230\u5982\u4e0b\u8f93\u51fa\uff1a<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">+------------------+-----------+\n| User             | Host      |\n+------------------+-----------+\n| root             | localhost |\n| mysql.session    | localhost |\n| mysql.sys        | localhost |\n| debian-sys-maint | localhost |\n+------------------+-----------+<\/pre>\n\n\n\n<p>\u8fd9\u4e2a\u8868\u663e\u793a\u4e86 <code>root<\/code> \u7528\u6237\u53ea\u80fd\u4ece <code>localhost<\/code>\uff08\u5373\u672c\u673a\uff09\u8fde\u63a5\u5230 MySQL\uff0c<code>mysql.session<\/code> \u548c\u5176\u4ed6\u7528\u6237\u4e5f\u662f\u5982\u6b64\u3002<\/p>\n\n\n\n<p>\u8fd9\u5c31\u662f\u67e5\u770b MySQL \u7528\u6237\u7684\u57fa\u672c\u65b9\u6cd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 MySQL \u4e2d\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6b65\u9aa4\u6765\u67e5\u770b\u6570\u636e\u5e93\u4e2d\u6240\u6709\u7528\u6237\u7684\u5217\u8868\uff1a 1. \u767b\u5f55\u5230 MySQL \u9996\u5148\uff0c\u4f60\u9700\u8981\u767b\u5f55\u5230 MySQL \u6570\u636e\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55\uff1a \u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u8f93\u5165 root \u7528\u6237\u7684\u5bc6\u7801\u3002 2. \u5207\u6362\u5230 mysql \u6570\u636e\u5e93 MySQL \u7684\u7528\u6237\u4fe1\u606f\u5b58\u50a8\u5728 mysql \u6570\u636e\u5e93\u4e2d\u7684 user \u8868\u4e2d\u3002\u4f60\u9700\u8981\u5207\u6362\u5230\u8be5\u6570\u636e\u5e93\uff1a 3. \u67e5\u8be2\u7528\u6237\u5217\u8868 \u8fd0\u884c\u4ee5\u4e0b SQL \u8bed\u53e5\u6765\u67e5\u770b\u6240\u6709\u7528\u6237\uff1a \u8fd9\u5c06\u663e\u793a\u6240\u6709\u7528\u6237\u4ee5\u53ca\u4ed6\u4eec\u5bf9\u5e94\u7684\u4e3b\u673a\uff08Host\uff09\u3002\u7528\u6237\u7684\u540d\u79f0\u5217\u5728 User \u5217\u4e2d\uff0c\u800c Host \u5217\u8868\u793a\u7528\u6237\u53ef\u4ee5\u4ece\u54ea\u4e2a\u4e3b\u673a\u8fde\u63a5\u5230 MySQL\u3002 4. \u9000\u51fa MySQL \u67e5\u770b\u5b8c\u7528\u6237\u5217\u8868\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa MySQL \u63a7\u5236\u53f0\uff1a \u89e3\u91ca\u7ed3\u679c \u793a\u4f8b \u5047\u8bbe\u4f60\u8fd0\u884c\u4e86\u4e0a\u9762\u7684 SELECT \u8bed\u53e5\uff0c\u4f60\u53ef\u80fd\u4f1a\u770b\u5230\u5982\u4e0b\u8f93\u51fa\uff1a \u8fd9\u4e2a\u8868\u663e\u793a\u4e86 root \u7528\u6237\u53ea\u80fd\u4ece localhost\uff08\u5373\u672c\u673a\uff09\u8fde\u63a5\u5230 MySQL\uff0cmysql.session \u548c\u5176\u4ed6\u7528\u6237\u4e5f\u662f\u5982\u6b64\u3002 \u8fd9\u5c31\u662f\u67e5\u770b MySQL \u7528\u6237\u7684\u57fa\u672c\u65b9\u6cd5\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[24,20],"class_list":["post-195","post","type-post","status-publish","format-standard","hentry","category-devops","tag-mysql","tag-ubuntu"],"_links":{"self":[{"href":"https:\/\/trantor.ink\/index.php?rest_route=\/wp\/v2\/posts\/195","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trantor.ink\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trantor.ink\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trantor.ink\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/trantor.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=195"}],"version-history":[{"count":2,"href":"https:\/\/trantor.ink\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions"}],"predecessor-version":[{"id":197,"href":"https:\/\/trantor.ink\/index.php?rest_route=\/wp\/v2\/posts\/195\/revisions\/197"}],"wp:attachment":[{"href":"https:\/\/trantor.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trantor.ink\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trantor.ink\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}