{"id":233378,"date":"2022-01-11T09:11:22","date_gmt":"2022-01-11T01:11:22","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=233378"},"modified":"2021-12-30T13:11:59","modified_gmt":"2021-12-30T05:11:59","slug":"mysql-linux-set","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/mysql-linux-set.html","title":{"rendered":"\u6559\u4f60mysql\u5982\u4f55\u589e\u52a0\u5916\u952e\u7ea6\u675f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5728\u672c\u7bc7\u6587\u7ae0\u91cc\u5c0f\u7f16\u7ed9\u5927\u5bb6\u6574\u7406\u7684\u662f\u4e00\u7bc7\u5173\u4e8emysql\u589e\u52a0\u5916\u952e\u7ea6\u675f\u5177\u4f53\u65b9\u6cd5\u53ca\u76f8\u5173\u5b9e\u4f8b\u5185\u5bb9\uff0c\u6709\u5174\u8da3\u7684\u670b\u53cb\u4eec\u53ef\u4ee5\u8ddf\u7740\u5b66\u4e60\u4e0b\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u672c\u6559\u7a0b\u64cd\u4f5c\u73af\u5883\uff1awindows7\u7cfb\u7edf\u3001mysql8\u7248\u672c\u3001Dell G3\u7535\u8111\u3002<\/p>\n

MySQL \u5916\u952e\u7ea6\u675f\uff08FOREIGN KEY\uff09\u662f\u8868\u7684\u4e00\u4e2a\u7279\u6b8a\u5b57\u6bb5\uff0c\u7ecf\u5e38\u4e0e\u4e3b\u952e\u7ea6\u675f\u4e00\u8d77\u4f7f\u7528\u3002\u5bf9\u4e8e\u4e24\u4e2a\u5177\u6709\u5173\u8054\u5173\u7cfb\u7684\u8868\u800c\u8a00\uff0c\u76f8\u5173\u8054\u5b57\u6bb5\u4e2d\u4e3b\u952e\u6240\u5728\u7684\u8868\u5c31\u662f\u4e3b\u8868\uff08\u7236\u8868\uff09\uff0c\u5916\u952e\u6240\u5728\u7684\u8868\u5c31\u662f\u4ece\u8868\uff08\u5b50\u8868\uff09\u3002<\/p>\n

\u5916\u952e\u7528\u6765\u5efa\u7acb\u4e3b\u8868\u4e0e\u4ece\u8868\u7684\u5173\u8054\u5173\u7cfb\uff0c\u4e3a\u4e24\u4e2a\u8868\u7684\u6570\u636e\u5efa\u7acb\u8fde\u63a5\uff0c\u7ea6\u675f\u4e24\u4e2a\u8868\u4e2d\u6570\u636e\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u3002<\/p>\n

\u5b9a\u4e49\u5916\u952e\u65f6\uff0c\u9700\u8981\u9075\u5b88\u4e0b\u5217\u89c4\u5219\uff1a<\/p>\n

\u4e3b\u8868\u5fc5\u987b\u5df2\u7ecf\u5b58\u5728\u4e8e\u6570\u636e\u5e93\u4e2d\uff0c\u6216\u8005\u662f\u5f53\u524d\u6b63\u5728\u521b\u5efa\u7684\u8868\u3002\u5982\u679c\u662f\u540e\u4e00\u79cd\u60c5\u51b5\uff0c\u5219\u4e3b\u8868\u4e0e\u4ece\u8868\u662f\u540c\u4e00\u4e2a\u8868\uff0c\u8fd9\u6837\u7684\u8868\u79f0\u4e3a\u81ea\u53c2\u7167\u8868\uff0c\u8fd9\u79cd\u7ed3\u6784\u79f0\u4e3a\u81ea\u53c2\u7167\u5b8c\u6574\u6027\u3002<\/p>\n

\u5fc5\u987b\u4e3a\u4e3b\u8868\u5b9a\u4e49\u4e3b\u952e\u3002<\/p>\n

\u4e3b\u952e\u4e0d\u80fd\u5305\u542b\u7a7a\u503c\uff0c\u4f46\u5141\u8bb8\u5728\u5916\u952e\u4e2d\u51fa\u73b0\u7a7a\u503c\u3002\u4e5f\u5c31\u662f\u8bf4\uff0c\u53ea\u8981\u5916\u952e\u7684\u6bcf\u4e2a\u975e\u7a7a\u503c\u51fa\u73b0\u5728\u6307\u5b9a\u7684\u4e3b\u952e\u4e2d\uff0c\u8fd9\u4e2a\u5916\u952e\u7684\u5185\u5bb9\u5c31\u662f\u6b63\u786e\u7684\u3002<\/p>\n

\u5728\u4e3b\u8868\u7684\u8868\u540d\u540e\u9762\u6307\u5b9a\u5217\u540d\u6216\u5217\u540d\u7684\u7ec4\u5408\u3002\u8fd9\u4e2a\u5217\u6216\u5217\u7684\u7ec4\u5408\u5fc5\u987b\u662f\u4e3b\u8868\u7684\u4e3b\u952e\u6216\u5019\u9009\u952e\u3002<\/p>\n

\u5916\u952e\u4e2d\u5217\u7684\u6570\u76ee\u5fc5\u987b\u548c\u4e3b\u8868\u7684\u4e3b\u952e\u4e2d\u5217\u7684\u6570\u76ee\u76f8\u540c\u3002<\/p>\n

\u5916\u952e\u4e2d\u5217\u7684\u6570\u636e\u7c7b\u578b\u5fc5\u987b\u548c\u4e3b\u8868\u4e3b\u952e\u4e2d\u5bf9\u5e94\u5217\u7684\u6570\u636e\u7c7b\u578b\u76f8\u540c\u3002<\/p>\n

mysql\u7ed9\u8868\u589e\u52a0\u5916\u952e\u7ea6\u675f<\/strong><\/div>\n

\u5916\u952e\u7ea6\u675f\u53ef\u4ee5\u5728\u4fee\u6539\u8868\u65f6\u6dfb\u52a0\uff0c\u4f46\u662f\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\u7684\u524d\u63d0\u662f\uff1a\u4ece\u8868\u4e2d\u5916\u952e\u5217\u4e2d\u7684\u6570\u636e\u5fc5\u987b\u4e0e\u4e3b\u8868\u4e2d\u4e3b\u952e\u5217\u4e2d\u7684\u6570\u636e\u4e00\u81f4\u6216\u8005\u662f\u6ca1\u6709\u6570\u636e\u3002<\/p>\n

\u5728\u4fee\u6539\u6570\u636e\u8868\u65f6\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\u7684\u8bed\u6cd5\u683c\u5f0f\u5982\u4e0b\uff1a<\/p>\n

\r\nALTER TABLE <\u6570\u636e\u8868\u540d> ADD CONSTRAINT <\u5916\u952e\u540d>\r\nFOREIGN KEY(<\u5217\u540d>) REFERENCES <\u4e3b\u8868\u540d> (<\u5217\u540d>);<\/pre>\n
\u793a\u4f8b<\/strong><\/div>\n

\u4fee\u6539\u6570\u636e\u8868 tb_emp2\uff0c\u5c06\u5b57\u6bb5 deptId \u8bbe\u7f6e\u4e3a\u5916\u952e\uff0c\u4e0e\u6570\u636e\u8868 tb_dept1 \u7684\u4e3b\u952e id \u8fdb\u884c\u5173\u8054<\/p>\n

\r\nmysql> ALTER TABLE tb_emp2\r\n-> ADD CONSTRAINT fk_tb_dept1\r\n-> FOREIGN KEY(deptId)\r\n-> REFERENCES tb_dept1(id);\r\nQuery OK, 0 rows affected (1.38 sec)\r\nRecords: 0 Duplicates: 0 Warnings: 0<\/pre>\n
\r\nmysql> SHOW CREATE TABLE tb_emp2\\G\r\n*************************** 1. row ***************************\r\nTable: tb_emp2\r\nCreate Table: CREATE TABLE `tb_emp2` (\r\n`id` int(11) NOT NULL,\r\n`name` varchar(30) DEFAULT NULL,\r\n`deptId` int(11) DEFAULT NULL,\r\n`salary` float DEFAULT NULL,\r\nPRIMARY KEY (`id`),\r\nKEY `fk_tb_dept1` (`deptId`),\r\nCONSTRAINT `fk_tb_dept1` FOREIGN KEY (`deptId`) REFERENCES `tb_dept1` (`id`)\r\n) ENGINE=InnoDB DEFAULT CHARSET=gb2312\r\n1 row in set (0.12 sec)<\/pre>\n

\u6ce8\u610f\uff1a\u5728\u4e3a\u5df2\u7ecf\u521b\u5efa\u597d\u7684\u6570\u636e\u8868\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\u65f6\uff0c\u8981\u786e\u4fdd\u6dfb\u52a0\u5916\u952e\u7ea6\u675f\u7684\u5217\u7684\u503c\u5168\u90e8\u6765\u6e90\u4e8e\u4e3b\u952e\u5217\uff0c\u5e76\u4e14\u5916\u952e\u5217\u4e0d\u80fd\u4e3a\u7a7a\u3002<\/p>\n

\u5185\u5bb9\u6269\u5c55\uff1a<\/strong><\/div>\n

\u4f7f\u7528\u5916\u952e\u7ea6\u675f\u7684\u65f6\u673a<\/p>\n

\u8001\u5b9e\u8bf4\uff0c\u5728MySQL\u4e2d\u4f7f\u7528InnoDB\u8868\u7684\u65f6\u5019\uff0c\u4e0d\u4e00\u5b9a\u975e\u7528\u5916\u952e\u7ea6\u675f\u4e0d\u53ef\uff0c\u7136\u800c\uff0c\u4e3a\u4e86\u5916\u952e\u7ea6\u675f\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u7684\u529f\u7528\uff0c\u6211\u4eec\u5c06\u901a\u8fc7\u524d\u9762\u63d0\u5230\u7684\u4f8b\u5b50\u7684\u4ee3\u7801\u8fdb\u884c\u5177\u4f53\u8bf4\u660e\u3002\u5b83\u5305\u62ec\u4e24\u4e2aMyISAM\u8868\uff0c\u5206\u522b\u7528\u4e8e\u5b58\u653e\u535a\u5ba2\u6587\u7ae0\u548c\u8bc4\u8bba\u3002<\/p>\n

\u5b9a\u4e49\u6570\u636e\u5e93\u6a21\u5f0f\u65f6\uff0c\u6211\u4eec\u8981\u5728\u8fd9\u4e24\u4e2a\u8868\u4e4b\u95f4\u5efa\u7acb\u8d77\u4e00\u5bf9\u591a\u7684\u5173\u7cfb\uff0c\u65b9\u6cd5\u662f\u5728\u5b58\u653e\u8bc4\u8bba\u7684\u8868\u4e2d\u521b\u5efa\u4e00\u4e2a\u5916\u952e\uff0c\u4ee5\u5c06\u5176\u4e2d\u7684\u6570\u636e\u884c(\u5373\u8bc4\u8bba)\u5bf9\u5e94\u5230\u7279\u5b9a\u7684\u535a\u5ba2\u6587\u7ae0\u3002\u4e0b\u9762\u662f\u521b\u5efa\u793a\u4f8bMyISAM\u8868\u7684\u57fa\u672cSQL\u4ee3\u7801\uff1a<\/p>\n

\r\nDROP TABLE IF EXISTS `test`.`blogs`;\r\n \r\nCREATE TABLE `test`.`blogs` (\r\n \r\n`id` INT(10) UNSIGNED AUTO_INCREMENT,\r\n \r\n`title` TEXT,\r\n \r\n`content` TEXT,\r\n \r\n`author` VARCHAR(45) DEFAULT NULL,\r\n \r\nPRIROSE KEY (`id`)\r\n \r\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;\r\n \r\n \r\nDROP TABLE IF EXISTS `test`.`comments`;\r\n \r\nCREATE TABLE `test`.`comments` (\r\n \r\n`id` INT(10) UNSIGNED AUTO_INCREMENT,\r\n \r\n`blog_id` INT(10) UNSIGNED DEFAULT NULL,\r\n \r\n`comment` TEXT,\r\n \r\n`author` VARCHAR(45) DEFAULT NULL,\r\n \r\nPRIROSE KEY (`id`)\r\n \r\n) ENGINE=MyISAM DEFAULT CHARSET=utf8;<\/pre>\n

\u5230\u6b64\u8fd9\u7bc7\u5173\u4e8emysql\u589e\u52a0\u5916\u952e\u7ea6\u675f\u5177\u4f53\u65b9\u6cd5\u7684\u6587\u7ae0\u5c31\u4ecb\u7ecd\u5230\u8fd9\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

\u672c\u6559\u7a0b\u64cd\u4f5c\u73af\u5883\uff1awindows7\u7cfb\u7edf\u3001mysql8\u7248\u672c\u3001Dell G3\u7535\u8111\u3002 MySQL \u5916\u952e\u7ea6\u675f\uff08FOREI […]<\/p>\n","protected":false},"author":1479,"featured_media":11367,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-233378","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/233378","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/1479"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=233378"}],"version-history":[{"count":3,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/233378\/revisions"}],"predecessor-version":[{"id":233381,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/233378\/revisions\/233381"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/11367"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=233378"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=233378"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=233378"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}