{"id":245,"date":"2023-02-24T06:04:06","date_gmt":"2023-02-23T22:04:06","guid":{"rendered":"https:\/\/www.appblog.cn\/?p=245"},"modified":"2023-04-30T15:19:58","modified_gmt":"2023-04-30T07:19:58","slug":"mysql-metadata","status":"publish","type":"post","link":"https:\/\/www.appblog.cn\/index.php\/2023\/02\/24\/mysql-metadata\/","title":{"rendered":"MySQL \u5143\u6570\u636e"},"content":{"rendered":"<p>\u5982\u679c\u60f3\u77e5\u9053MySQL\u4ee5\u4e0b\u4e09\u79cd\u4fe1\u606f\uff1a<\/p>\n<ul>\n<li>\u67e5\u8be2\u7ed3\u679c\u4fe1\u606f\uff1a<code>SELECT<\/code>, <code>UPDATE<\/code>\u6216<code>DELETE<\/code>\u8bed\u53e5\u5f71\u54cd\u7684\u8bb0\u5f55\u6570<\/li>\n<li>\u6570\u636e\u5e93\u548c\u6570\u636e\u8868\u7684\u4fe1\u606f\uff1a\u5305\u542b\u6570\u636e\u5e93\u53ca\u6570\u636e\u8868\u7684\u7ed3\u6784\u4fe1\u606f<\/li>\n<li>MySQL\u670d\u52a1\u5668\u4fe1\u606f\uff1a\u5305\u542b\u6570\u636e\u5e93\u670d\u52a1\u5668\u7684\u5f53\u524d\u72b6\u6001\uff0c\u7248\u672c\u53f7\u7b49<\/li>\n<\/ul>\n<p><!-- more --><\/p>\n<p>\u5728MySQL\u7684\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u83b7\u53d6\u4ee5\u4e0a\u670d\u52a1\u5668\u4fe1\u606f\u3002\u4f46\u5982\u679c\u4f7f\u7528PHP\u7b49\u811a\u672c\u8bed\u8a00\uff0c\u9700\u8981\u8c03\u7528\u7279\u5b9a\u7684\u63a5\u53e3\u51fd\u6570\u6765\u83b7\u53d6\u3002<\/p>\n<h2>\u83b7\u53d6\u67e5\u8be2\u8bed\u53e5\u5f71\u54cd\u7684\u8bb0\u5f55\u6570<\/h2>\n<p>\u5728PHP\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528<code>mysqli_affected_rows()<\/code>\u51fd\u6570\u6765\u83b7\u53d6\u67e5\u8be2\u8bed\u53e5\u5f71\u54cd\u7684\u8bb0\u5f55\u6570<\/p>\n<pre><code class=\"language-php\">$result = mysqli_query($conn_id, $query);\n# \u5982\u679c\u67e5\u8be2\u5931\u8d25\u8fd4\u56de\n$count = ($result ? mysqli_affected_rows($conn_id) : 0);\nprint (&quot;$count \u6761\u6570\u636e\u88ab\u5f71\u54cd\\n&quot;);<\/code><\/pre>\n<h2>\u6570\u636e\u5e93\u548c\u6570\u636e\u8868\u5217\u8868<\/h2>\n<p>\u53ef\u4ee5\u5f88\u5bb9\u6613\u7684\u5728MySQL\u670d\u52a1\u5668\u4e2d\u83b7\u53d6\u6570\u636e\u5e93\u548c\u6570\u636e\u8868\u5217\u8868\u3002\u5982\u679c\u6ca1\u6709\u8db3\u591f\u7684\u6743\u9650\uff0c\u7ed3\u679c\u5c06\u8fd4\u56de null<\/p>\n<p>\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>SHOW TABLES<\/code>\u6216<code>SHOW DATABASES<\/code>\u8bed\u53e5\u6765\u83b7\u53d6\u6570\u636e\u5e93\u548c\u6570\u636e\u8868\u5217\u8868<\/p>\n<p>\u4ee5\u4e0bPHP\u5b9e\u4f8b\u8f93\u51faMySQL\u670d\u52a1\u5668\u4e0a\u7684\u6240\u6709\u6570\u636e\u5e93\uff1a<\/p>\n<pre><code class=\"language-php\">$dbhost = &#039;localhost:3306&#039;;  \/\/ mysql\u670d\u52a1\u5668\u4e3b\u673a\u5730\u5740\n$dbuser = &#039;root&#039;;            \/\/ mysql\u7528\u6237\u540d\n$dbpass = &#039;123456&#039;;          \/\/ mysql\u7528\u6237\u540d\u5bc6\u7801\n$conn = mysqli_connect($dbhost, $dbuser, $dbpass);\nif(!$conn)\n{\n    die(&#039;\u8fde\u63a5\u5931\u8d25: &#039; . mysqli_error($conn));\n}\n\/\/ \u8bbe\u7f6e\u7f16\u7801\uff0c\u9632\u6b62\u4e2d\u6587\u4e71\u7801\n$db_list = mysqli_query($conn, &#039;SHOW DATABASES&#039;);\nwhile ($db = mysqli_fetch_object($db_list))\n{\n  echo $db-&gt;Database . &quot;&lt;br \/&gt;&quot;;\n}\nmysqli_close($conn);<\/code><\/pre>\n<h2>\u83b7\u53d6\u670d\u52a1\u5668\u5143\u6570\u636e<\/h2>\n<p>\u4ee5\u4e0b\u547d\u4ee4\u8bed\u53e5\u53ef\u4ee5\u5728 MySQL \u7684\u547d\u4ee4\u63d0\u793a\u7b26\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u5728\u811a\u672c\u4e2d\u4f7f\u7528\uff0c\u5982PHP\u811a\u672c<\/p>\n<ul>\n<li><code>SELECT VERSION()<\/code> \u670d\u52a1\u5668\u7248\u672c\u4fe1\u606f<\/li>\n<li><code>SELECT DATABASE()<\/code> \u5f53\u524d\u6570\u636e\u5e93\u540d (\u6216\u8005\u8fd4\u56de\u7a7a)<\/li>\n<li><code>SELECT USER()<\/code> \u5f53\u524d\u7528\u6237\u540d<\/li>\n<li><code>SHOW STATUS<\/code> \u670d\u52a1\u5668\u72b6\u6001<\/li>\n<li><code>SHOW VARIABLES<\/code> \u670d\u52a1\u5668\u914d\u7f6e\u53d8\u91cf<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u60f3\u77e5\u9053MySQL\u4ee5\u4e0b\u4e09\u79cd\u4fe1\u606f\uff1a \u67e5\u8be2\u7ed3\u679c\u4fe1\u606f\uff1aSELECT, UPDATE\u6216DELETE\u8bed\u53e5\u5f71\u54cd\u7684\u8bb0\u5f55\u6570  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13],"tags":[],"class_list":["post-245","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/245","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/comments?post=245"}],"version-history":[{"count":0,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/posts\/245\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/media?parent=245"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/categories?post=245"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appblog.cn\/index.php\/wp-json\/wp\/v2\/tags?post=245"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}