{"id":94,"date":"2026-03-16T22:16:57","date_gmt":"2026-03-16T14:16:57","guid":{"rendered":"http:\/\/150.158.139.84\/?p=94"},"modified":"2026-03-16T22:16:57","modified_gmt":"2026-03-16T14:16:57","slug":"mysql%e5%85%a5%e9%97%a8","status":"publish","type":"post","link":"https:\/\/blog.echoxx.tech\/index.php\/2026\/03\/16\/mysql%e5%85%a5%e9%97%a8\/","title":{"rendered":"MySQL\u5165\u95e8"},"content":{"rendered":"\n<h1 class=\"wp-block-heading\">MySQL \u5e38\u7528\u547d\u4ee4\uff08\u901f\u8bb0\u7248\uff09<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u26a0\ufe0f <strong>\u8bed\u53e5\u5fc5\u987b\u4ee5 <\/strong><strong><code>;<\/code><\/strong><strong> \u7ed3\u5c3e<\/strong><code>--<\/code> \u540e\u662f\u6ce8\u91ca\uff0c\u53ef\u5220\u9664<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5e93\u64cd\u4f5c<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW DATABASES;           -- \u67e5\u770b\u6240\u6709\u6570\u636e\u5e93<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE name;   -- \u521b\u5efa\u6570\u636e\u5e93<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT DATABASE();    -- \u67e5\u770b\u5f53\u524d\u7684\u6570\u636e\u5e93<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>DROP DATABASE name;     -- \u5220\u9664\u6570\u636e\u5e93<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>USE name;               -- \u5207\u6362\u5230 testdb \u6570\u636e\u5e93<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW TABLES;  -- \u67e5\u770b\u5f53\u524d\u6570\u636e\u5e93\u7684\u6240\u6709\u8868<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u8868\u64cd\u4f5c<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW TABLES;   -- \u67e5\u770b\u5f53\u524d\u6570\u636e\u5e93\u7684\u6240\u6709\u8868<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE name(\n    id INT PRIMARY KEY AUTO_INCREMENT,\n    name VARCHAR(50),\n    age INT\n);  -- \u521b\u5efa\u8868<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>INSERT INTO users (name, age) VALUES ('Tom', 22);   -- \u63d2\u5165\nSELECT * FROM users;         -- \u67e5\u8be2\nUPDATE users SET age=23 WHERE name='Tom'; -- \u66f4\u65b0\nDELETE FROM users WHERE id=1; -- \u5220\u9664<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>DESC name;    -- \u67e5\u770b\u8868\u7ed3\u6784<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>DROP TABLE name;  -- \u5220\u9664\u8868<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u589e\u5220\u6539\u67e5\uff08CRUD\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SHOW TABLES;   -- \u67e5\u770b\u5f53\u524d\u6570\u636e\u5e93\u7684\u6240\u6709\u8868<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE TABLE users (\n    id INT PRIMARY KEY AUTO_INCREMENT,\n    name VARCHAR(50),\n    age INT\n);  -- \u521b\u5efa\u8868<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>DESC users;    -- \u67e5\u770b\u8868\u7ed3\u6784<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>DROP TABLE users;  -- \u5220\u9664\u8868<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u7528\u6237\u7ba1\u7406\uff08\u53ef\u9009\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE USER 'testuser'@'localhost' IDENTIFIED BY '123456'; -- \u521b\u5efa\u7528\u6237<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>GRANT ALL PRIVILEGES ON testdb.* TO 'testuser'@'localhost'; -- \u6388\u6743<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>FLUSH PRIVILEGES;  -- \u5237\u65b0\u6743\u9650<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728 MySQL \u91cc\u67e5\u770b\u5f53\u524d\u767b\u5f55\u7684\u7528\u6237\u540d<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT USER();\n\u4f1a\u8fd4\u56de\u7528\u6237\u540d@\u4e3b\u673a\uff0c\u6bd4\u5982\uff1a\n+----------------+\n| USER()         |\n+----------------+\n| root@localhost |\n+----------------+\n\n\u5982\u679c\u4f60\u53ea\u60f3\u770b<strong>\u7528\u6237\u540d<\/strong>\uff08\u4e0d\u5e26 @ \u4e3b\u673a\u90e8\u5206\uff09\uff0c\u53ef\u4ee5\u7528\uff1a\nSELECT SUBSTRING_INDEX(USER(), '@', 1);\n\u53ea\u4f1a\u8fd4\u56de\u7528\u6237\u540d\uff0c\u6bd4\u5982\uff1a\n+---------------------------------+\n| SUBSTRING_INDEX(USER(), '@', 1) |\n+---------------------------------+\n| root                            |\n+---------------------------------+<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>MySQL \u5e38\u7528\u547d\u4ee4\uff08\u901f\u8bb0\u7248\uff09 \u26a0\ufe0f \u8bed\u53e5\u5fc5\u987b\u4ee5 ; \u7ed3\u5c3e&#8211; \u540e\u662f\u6ce8\u91ca\uff0c\u53ef\u5220\u9664 \u6570\u636e\u5e93\u64cd\u4f5c \u6570\u636e\u8868\u64cd\u4f5c \u589e\u5220 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-94","post","type-post","status-publish","format-standard","hentry","category-learning"],"_links":{"self":[{"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/posts\/94","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/comments?post=94"}],"version-history":[{"count":2,"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions"}],"predecessor-version":[{"id":96,"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/posts\/94\/revisions\/96"}],"wp:attachment":[{"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/media?parent=94"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/categories?post=94"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.echoxx.tech\/index.php\/wp-json\/wp\/v2\/tags?post=94"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}