{"id":6227,"date":"2024-11-14T09:02:34","date_gmt":"2024-11-14T01:02:34","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6227\/"},"modified":"2024-11-14T09:02:34","modified_gmt":"2024-11-14T01:02:34","slug":"%e5%a6%82%e4%bd%95%e9%aa%8c%e8%af%81mysql%e5%ae%89%e8%a3%85%e6%88%90%e5%8a%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6227\/","title":{"rendered":"\u5982\u4f55\u9a8c\u8bc1mysql\u5b89\u88c5\u6210\u529f"},"content":{"rendered":"<p><strong>\u5982\u4f55\u9a8c\u8bc1  \u5b89\u88c5\u6210\u529f<\/strong><\/p>\n<p>\u8981\u9a8c\u8bc1 MySQL \u5b89\u88c5\u662f\u5426\u6210\u529f\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<p><strong>1. \u68c0\u67e5\u662f\u5426\u80fd\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668<\/strong><\/p>\n<ul>\n<li>\u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u3002<\/li>\n<li>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5176\u4e2d root \u662f MySQL \u7684\u9ed8\u8ba4\u7528\u6237\u540d\uff0cpassword \u662f\u5bc6\u7801\uff1a<\/li>\n<\/ul>\n<pre>mysql -u root -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u8f93\u5165\u5bc6\u7801\u3002<\/li>\n<li>\u5982\u679c\u8fde\u63a5\u6210\u529f\uff0c\u4f60\u4f1a\u770b\u5230 MySQL \u7684\u63d0\u793a\u7b26\uff1a<\/li>\n<\/ul>\n<pre>mysql&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u67e5\u770b MySQL \u7248\u672c<\/strong><\/p>\n<ul>\n<li>\u5728 MySQL \u63d0\u793a\u7b26\u4e0b\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/li>\n<\/ul>\n<pre>SELECT VERSION();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u8fd9\u5c06\u663e\u793a MySQL \u670d\u52a1\u5668\u7684\u7248\u672c\u3002<\/li>\n<\/ul>\n<p><strong>3. \u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93<\/strong><\/p>\n<ul>\n<li>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5176\u4e2d my_database \u662f\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\uff1a<\/li>\n<\/ul>\n<pre>CREATE DATABASE my_database;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5982\u679c\u521b\u5efa\u6210\u529f\uff0c\u4f60\u4f1a\u770b\u5230\u5982\u4e0b\u6d88\u606f\uff1a<\/li>\n<\/ul>\n<pre>Query OK, 1 row affected (0.00 sec)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u521b\u5efa\u4e00\u4e2a\u8868<\/strong><\/p>\n<ul>\n<li>\u9009\u62e9\u65b0\u521b\u5efa\u7684\u6570\u636e\u5e93\uff1a<\/li>\n<\/ul>\n<pre>USE my_database;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5176\u4e2d my_table \u662f\u8981\u521b\u5efa\u7684\u8868\u7684\u540d\u79f0\uff0cid\u3001name \u548c age \u662f\u5217\u540d\uff1a<\/li>\n<\/ul>\n<pre>CREATE TABLE my_table (\n  id INT NOT NULL AUTO_INCREMENT,\n  name VARCHAR(255) NOT NULL,\n  age INT NOT NULL,\n  PRIMARY KEY (id)\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5982\u679c\u521b\u5efa\u6210\u529f\uff0c\u4f60\u4f1a\u770b\u5230\u5982\u4e0b\u6d88\u606f\uff1a<\/li>\n<\/ul>\n<pre>Query OK, 0 rows affected (0.00 sec)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u63d2\u5165\u4e00\u4e9b\u6570\u636e<\/strong><\/p>\n<ul>\n<li>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5176\u4e2d John Doe \u548c 25 \u5206\u522b\u662f name \u548c age \u5217\u7684\u503c\uff1a<\/li>\n<\/ul>\n<pre>INSERT INTO my_table (name, age) VALUES ('John Doe', 25);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5982\u679c\u63d2\u5165\u6210\u529f\uff0c\u4f60\u4f1a\u770b\u5230\u5982\u4e0b\u6d88\u606f\uff1a<\/li>\n<\/ul>\n<pre>Query OK, 1 row affected (0.00 sec)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u67e5\u8be2\u6570\u636e<\/strong><\/p>\n<ul>\n<li>\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5176\u4e2d * \u8868\u793a\u67e5\u8be2\u6240\u6709\u5217\uff1a<\/li>\n<\/ul>\n<pre>SELECT * FROM my_table;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5982\u679c\u67e5\u8be2\u6210\u529f\uff0c\u4f60\u4f1a\u770b\u5230\u521a\u63d2\u5165\u7684\u6570\u636e\uff1a<\/li>\n<\/ul>\n<pre>+----+-------+------+\n| id | name   | age  |\n+----+-------+------+\n| 1  | John Doe | 25   |\n+----+-------+------+<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u5982\u679c\u4f60\u80fd\u6210\u529f\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668\uff0c\u67e5\u770b\u7248\u672c\uff0c\u521b\u5efa\u6570\u636e\u5e93\u3001\u8868\uff0c\u63d2\u5165\u548c\u67e5\u8be2\u6570\u636e\uff0c\u5219\u8868\u793a MySQL \u5b89\u88c5\u5df2\u6210\u529f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u9a8c\u8bc1\u5b89\u88c5\u6210\u529f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u9a8c\u8bc1 \u5b89\u88c5\u6210\u529f \u8981\u9a8c\u8bc1 MySQL \u5b89\u88c5\u662f\u5426\u6210\u529f\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a 1. \u68c0\u67e5\u662f\u5426\u80fd\u8fde\u63a5\u5230 MySQL \u670d\u52a1\u5668 \u6253\u5f00\u7ec8\u7aef\u6216\u547d\u4ee4\u63d0\u793a\u7b26\u3002 \u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5176\u4e2d root \u662f MySQL \u7684\u9ed8\u8ba4\u7528\u6237\u540d\uff0cpassword \u662f\u5bc6\u7801\uff1a mysql -u root -p \u767b\u5f55\u540e\u590d\u5236 \u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u8f93\u5165\u5bc6\u7801\u3002 \u5982\u679c\u8fde\u63a5\u6210\u529f\uff0c\u4f60\u4f1a\u770b\u5230 MySQL \u7684\u63d0\u793a\u7b26\uff1a mysql&gt; \u767b\u5f55\u540e\u590d\u5236 2. \u67e5\u770b MySQL \u7248\u672c \u5728 MySQL \u63d0\u793a\u7b26\u4e0b\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a SELECT VERSION(); \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u5c06\u663e\u793a MySQL \u670d\u52a1\u5668\u7684\u7248\u672c\u3002 3. \u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93 \u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff0c\u5176\u4e2d my_database \u662f\u8981\u521b\u5efa\u7684\u6570\u636e\u5e93\u7684\u540d\u79f0\uff1a CREATE DATABASE my_database; \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u521b\u5efa\u6210\u529f\uff0c\u4f60\u4f1a\u770b\u5230\u5982\u4e0b\u6d88\u606f\uff1a Query OK, 1 row affected [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6227","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6227","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6227"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6227\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}