
{"id":2359,"date":"2020-10-13T09:27:34","date_gmt":"2020-10-13T01:27:34","guid":{"rendered":"http:\/\/admin.evshou.com\/?p=2359"},"modified":"2020-10-15T15:42:30","modified_gmt":"2020-10-15T07:42:30","slug":"2020javaweb%e6%95%99%e7%a8%8b%e4%b9%8bmysql%e6%95%b0%e6%8d%ae%e5%ba%93%e4%ba%8b%e5%8a%a1%e4%bb%a5%e5%8f%8a%e8%a7%86%e5%9b%be","status":"publish","type":"post","link":"https:\/\/www.9713job.com\/?p=2359","title":{"rendered":"2020Javaweb\u6559\u7a0b\u4e4bmysql\u6570\u636e\u5e93\u4e8b\u52a1\u4ee5\u53ca\u89c6\u56fe"},"content":{"rendered":"<h3>2020Javaweb\u6559\u7a0b\u4e4bmysql\u6570\u636e\u5e93\u4e8b\u52a1\u4ee5\u53ca\u89c6\u56fe<\/h3>\n<p><span style=\"color: #ff0000;\">\u4e8b\u52a1\u6982\u8ff0<\/span><\/p>\n<p>\u200b \u4e00\u7ec4\u8981\u4e48\u540c\u65f6\u6267\u884c\u6210\u529f\uff0c\u8981\u4e48\u540c\u65f6\u5931\u8d25\u7684SQL\u8bed\u53e5\u3002\u662f\u6570\u636e\u5e93\u64cd\u4f5c\u7684\u4e00\u4e2a\u4e0d\u80fd\u5206\u5272\u6267\u884c\u5355\u5143\u3002<\/p>\n<p>\u6570\u636e\u5e93\u4e8b\u52a1(Database Transaction) \uff0c\u662f\u6307\u4f5c\u4e3a\u5355\u4e2a\u903b\u8f91\u5de5\u4f5c\u5355\u5143\u6267\u884c\u7684\u4e00\u7cfb\u5217\u64cd\u4f5c\uff0c\u8981\u4e48\u5b8c\u5168\u5730\u6267\u884c\uff0c\u8981\u4e48\u5b8c\u5168\u5730\u4e0d\u6267\u884c\u3002<\/p>\n<p><!--more--><\/p>\n<p><span style=\"color: #ff0000;\">\u4e8b\u52a1\u5f00\u59cb\u4e8e<\/span><\/p>\n<p>&#8211; \u8fde\u63a5\u5230\u6570\u636e\u5e93\u4e0a\uff0c\u5e76\u6267\u884c\u4e00\u6761DML\u8bed\u53e5insert\u3001update\u6216delete<br \/>\n&#8211; \u524d\u4e00\u4e2a\u4e8b\u52a1\u7ed3\u675f\u540e\uff0c\u53c8\u8f93\u5165\u4e86\u53e6\u4e00\u6761DML\u8bed\u53e5<\/p>\n<p><span style=\"color: #ff0000;\">\u4e8b\u52a1\u7ed3\u675f\u4e8e<\/span><\/p>\n<p>&#8211; \u6267\u884ccommit\u6216rollback\u8bed\u53e5\u3002<br \/>\n&#8211; \u6267\u884c\u4e00\u6761DDL\u8bed\u53e5\uff0c\u4f8b\u5982create table\u8bed\u53e5\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f1a\u81ea\u52a8\u6267\u884ccommit\u8bed\u53e5\u3002<br \/>\n&#8211; \u6267\u884c\u4e00\u6761DDL\u8bed\u53e5\uff0c\u4f8b\u5982grant\u8bed\u53e5\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f1a\u81ea\u52a8\u6267\u884ccommit\u3002<br \/>\n&#8211; \u65ad\u5f00\u4e0e\u6570\u636e\u5e93\u7684\u8fde\u63a5<br \/>\n&#8211; \u6267\u884c\u4e86\u4e00\u6761DML\u8bed\u53e5\uff0c\u8be5\u8bed\u53e5\u5374\u5931\u8d25\u4e86\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e2d\uff0c\u4f1a\u4e3a\u8fd9\u4e2a\u65e0\u6548\u7684DML\u8bed\u53e5\u6267\u884crollback\u8bed\u53e5\u3002<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u4e8b\u52a1\u56db\u5927\u7279\u6027ACID<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\">&#8211; Atomicity(\u539f\u5b50\u6027)<\/span><\/p>\n<p>\u8868\u793a\u4e00\u4e2a\u4e8b\u52a1\u5185\u7684\u6240\u6709\u64cd\u4f5c\u662f\u4e00\u4e2a\u6574\u4f53\uff0c\u8981\u4e48\u5168\u90e8\u6210\u529f\uff0c\u8981\u4e48\u5168\u90e8\u5931\u8d25<\/p>\n<p><span style=\"color: #ff0000;\">&#8211; Consistency(\u4e00\u81f4\u6027)<\/span><\/p>\n<p>\u8868\u793a\u4e00\u4e2a\u4e8b\u52a1\u5185\u6709\u4e00\u4e2a\u64cd\u4f5c\u5931\u8d25\u65f6\uff0c\u6240\u6709\u7684\u66f4\u6539\u8fc7\u7684\u6570\u636e\u90fd\u5fc5\u987b\u56de\u6eda\u5230\u4fee\u6539\u524d\u72b6\u6001<\/p>\n<p><span style=\"color: #ff0000;\">&#8211; Isolation(\u9694\u79bb\u6027)<\/span><\/p>\n<p>\u4e8b\u52a1\u67e5\u770b\u6570\u636e\u64cd\u4f5c\u65f6\u6570\u636e\u6240\u5904\u7684\u72b6\u6001\uff0c\u8981\u4e48\u662f\u53e6\u4e00\u5e76\u53d1\u4e8b\u52a1\u4fee\u6539\u5b83\u4e4b\u524d\u7684\u72b6\u6001\uff0c\u8981\u4e48\u662f\u53e6\u4e00\u4e8b\u52a1\u4fee\u6539\u5b83\u4e4b\u540e\u7684\u72b6\u6001\uff0c\u4e8b\u52a1\u4e0d\u4f1a\u67e5\u770b\u4e2d\u95f4\u72b6\u6001\u7684\u6570\u636e\u3002<\/p>\n<p><span style=\"color: #ff0000;\">&#8211; Durability(\u6301\u4e45\u6027)<\/span><\/p>\n<p>\u6301\u4e45\u6027\u4e8b\u52a1\u5b8c\u6210\u4e4b\u540e\uff0c\u5b83\u5bf9\u4e8e\u7cfb\u7edf\u7684\u5f71\u54cd\u662f\u6c38\u4e45\u6027\u7684\u3002<\/p>\n<p><span style=\"color: #ff0000;\">\u5f00\u542f\u4e8b\u52a1<\/span><br \/>\nSTART TRANSACTION;<br \/>\n<span style=\"color: #ff0000;\">\u4e8b\u52a1\u5185\u6570\u636e\u64cd\u4f5c\u8bed\u53e5<\/span><br \/>\nUPDATE account SET money=money-1000 WHERE id=1;<br \/>\nUPDATE account SET money=money+1000 WHERE id=2;<br \/>\n<span style=\"color: #ff0000;\">\u63d0\u4ea4\u4e8b\u52a1<\/span><br \/>\nCOMMIT;<br \/>\n<span style=\"color: #ff0000;\">\u56de\u6eda<\/span><br \/>\nROLLBACK;<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u65f6\u95f4\u5904\u7406<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\">CURDATE()<\/span>\uff1aSELECT CURDATE()#\u83b7\u53d6\u5f53\u524d\u65e5\u671f<\/p>\n<p><span style=\"color: #ff0000;\">CURTIME()<\/span>\uff1aSELECT CURTIME()#\u83b7\u53d6\u5f53\u524d\u65f6\u95f4<\/p>\n<p><span style=\"color: #ff0000;\">NOW()<\/span>\uff1aSELECT NOW()#\u5f53\u524d\u65e5\u671f\u548c\u65f6\u95f4<\/p>\n<p><span style=\"color: #ff0000;\">WEEK(date)<\/span>\uff1aSELECT WEEK(NOW())#\u7b2c\u51e0\u5468\uff0c\u4ece1\u6708\u5f00\u59cb\u8ba1\u7b97<\/p>\n<p><span style=\"color: #ff0000;\">YEAR(date)<\/span>\uff1aSELECT YEAR(NOW())#\u83b7\u53d6\u5e74\u4efd<\/p>\n<p><span style=\"color: #ff0000;\">HOUR(time)<\/span>\uff1aSELECT HOUR(NOW())#\u83b7\u53d6\u5c0f\u65f6<\/p>\n<p><span style=\"color: #ff0000;\">MINUTE(time)<\/span>\uff1aSELECT MINUTE(NOW())#\u83b7\u53d6\u5206\u949f<\/p>\n<p><span style=\"color: #ff0000;\">DATEDIFF(date1,date2)<\/span>\uff1aSELECT DATEDIFF(NOW(),&#8217;2010-6-6&#8242;)#\u8fd4\u56de\u4e4b\u95f4\u76f8\u9694\u7684\u5929\u6570<\/p>\n<p><span style=\"color: #ff0000;\">ADDDATE(date,n)<\/span>\uff1aSELECT ADDDATE(NOW(),7)#\u65e5\u671f\u52a0n\u5929\u540e\u7684\u65e5\u671f<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u5b57\u7b26\u4e32\u5904\u7406<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\">concat()<\/span>\uff1aSELECT CONCAT(&#8216;my&#8217;,&#8217;s&#8217;,&#8217;q&#8217;,&#8217;l&#8217;) #\u5b57\u7b26\u4e32\u8fde\u63a5<\/p>\n<p><span style=\"color: #ff0000;\">insert()<\/span>\uff1aSELECT INSERT(&#8216;boss&#8217;,2,1,&#8217;i&#8217;) #\u5b57\u7b26\u4e32\u66ff\u6362<\/p>\n<p><span style=\"color: #ff0000;\">lower(str)<\/span>\uff1aSELECT LOWER(&#8216;APPLE&#8217;)#\u5c06\u5b57\u7b26\u4e32\u8f6c\u5c0f\u5199<\/p>\n<p><span style=\"color: #ff0000;\">upper(str)<\/span>\uff1aSELECT UPPER(&#8216;apple&#8217;) #\u5c06\u5b57\u7b26\u4e32\u8f6c\u5927\u5199<\/p>\n<p><span style=\"color: #ff0000;\">substring(str,pos,num)<\/span>\uff1aSELECT SUBSTRING(&#8216;appole&#8217;,1,4) #\u5b57\u7b26\u4e32\u622a\u53d6<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u5bfc\u51fa\/\u5bfc\u5165\u6570\u636e\u5e93<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\">\u5bfc\u51fa\u6570\u636e\u5e93<\/span>\uff1a<br \/>\nmysqldump -uroot -p demos &gt;\u76ee\u6807\u8def\u5f84<\/p>\n<p><span style=\"color: #ff0000;\">\u5bfc\u5165\u6570\u636e\u5e93<\/span>\uff1a<br \/>\nmysql -uroot -p<br \/>\n\u5207\u6362\u6570\u636e\u5e93\uff0csource \u6570\u636e\u5e93\u6587\u4ef6\u5730\u5740<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u521b\u5efa\u7528\u6237\u548c\u6388\u6743<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\">\u521b\u5efa\u7528\u6237<\/span>\uff1a<br \/>\nCREATE USER &#8216;\u7528\u6237\u540d&#8217; IDENTIFIED BY &#8216;\u5bc6\u7801&#8217;<\/p>\n<p><span style=\"color: #ff0000;\">\u6388\u6743<\/span>\uff1a<br \/>\nGRANT ALL ON \u5e93\u540d TO &#8216;\u7528\u6237\u540d&#8217;<\/p>\n<p><span style=\"color: #ff0000;\">\u64a4\u9500\u6388\u6743<\/span>\uff1a<br \/>\nREVOKE ALL ON \u5e93\u540d FROM &#8216;\u7528\u6237\u540d&#8217;<\/p>\n<p><span style=\"color: #ff0000;\">\u5220\u9664\u7528\u6237<\/span>\uff1a<br \/>\nDROP USER &#8216;admin&#8217;<\/p>\n<p>&nbsp;<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u89c6\u56fe<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\">\u4ec0\u4e48\u662f\u89c6\u56fe\uff1f<\/span><\/p>\n<p>\u89c6\u56fe\uff0c\u865a\u62df\u8868\uff0c\u4ece\u4e00\u4e2a\u8868\u6216\u591a\u4e2a\u8868\u4e2d\u5bfc\u51fa\u6765\u7684\u8868\uff0c\u4f5c\u7528\u548c\u771f\u5b9e\u8868\u4e00\u6837\uff0c\u5305\u542b\u4e00\u7cfb\u5217\u5e26\u6709\u884c\u548c\u5217\u7684\u6570\u636e \u89c6\u56fe\u4e2d\uff0c\u7528\u6237\u53ef\u4ee5\u4f7f\u7528SELECT\u8bed\u53e5\u67e5\u8be2\u6570\u636e\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528INSERT\uff0cUPDATE\uff0cDELETE\u4fee\u6539\u8bb0\u5f55\uff0c\u89c6\u56fe\u53ef\u4ee5\u4f7f\u7528\u6237\u64cd\u4f5c\u65b9\u4fbf\uff0c\u5e76\u4fdd\u969c\u6570\u636e\u5e93\u7cfb\u7edf\u5b89\u5168\u3002<\/p>\n<p><span style=\"color: #ff0000;\">\u89c6\u56fe\u7684\u4f18\u70b9\u548c\u7f3a\u70b9<\/span><\/p>\n<p>\u4f18\u70b9<br \/>\n\u7b80\u5355\u5316\uff0c\u6570\u636e\u6240\u89c1\u5373\u6240\u5f97<br \/>\n\u5b89\u5168\u6027\uff0c\u7528\u6237\u53ea\u80fd\u67e5\u8be2\u6216\u4fee\u6539\u4ed6\u4eec\u6240\u80fd\u89c1\u5230\u5f97\u5230\u7684\u6570\u636e<br \/>\n\u903b\u8f91\u72ec\u7acb\u6027\uff0c\u53ef\u4ee5\u5c4f\u853d\u771f\u5b9e\u8868\u7ed3\u6784\u53d8\u5316\u5e26\u6765\u7684\u5f71\u54cd<\/p>\n<p>\u7f3a\u70b9<br \/>\n\u6027\u80fd\u76f8\u5bf9\u8f83\u5dee\uff0c\u7b80\u5355\u7684\u67e5\u8be2\u4e5f\u4f1a\u53d8\u5f97\u7a0d\u663e\u590d\u6742<br \/>\n\u4fee\u6539\u4e0d\u65b9\u4fbf\uff0c\u7279\u53d8\u662f\u590d\u6742\u7684\u805a\u5408\u89c6\u56fe\u57fa\u672c\u65e0\u6cd5\u4fee\u6539<\/p>\n<p><span style=\"color: #ff0000;\">\u521b\u5efa\u89c6\u56fe\uff1a<br \/>\n<\/span>CREATE VIEW \u89c6\u56fe\u540d AS SELECT*FROM emp<\/p>\n<p><span style=\"color: #ff0000;\">\u4f7f\u7528\u89c6\u56fe<\/span>\uff1aSELECT*FROM \u89c6\u56fe\u540d<\/p>\n<p><span style=\"color: #ff0000;\">\u6ce8\u610f\uff1a\u5982\u679c\u89c6\u56fe\u5305\u542b\u4ee5\u4e0b\u7ed3\u6784\u4e2d\u7684\u4efb\u4f55\u4e00\u79cd\uff0c\u5219\u8be5\u89c6\u56fe\u4e0d\u53ef\u66f4\u65b0<\/span>\uff1a<br \/>\n\u805a\u5408\u51fd\u6570\u3001DISTINCT\u3001 GROUP BY\u3001HAVING\u3001UNION\u3001 UNION ALL\u3001FROM\u5b50\u53e5\u4e2d\u7684\u4e0d\u53ef\u66f4\u65b0\u7684\u591a\u4e2a\u8868\u3001WHERE\u5b50\u53e5\u4e2d\u7684\u5b50\u67e5\u8be2\uff0c\u5f15\u7528FROM\u5b50\u53e5\u4e2d\u7684\u8868<\/p>\n<p><strong><span style=\"color: #ff0000;\">\u89c6\u56fe\u7684\u4fee\u6539<\/span><\/strong><\/p>\n<p><span style=\"color: #ff0000;\">#\u5982\u679c\u5b58\u5728\u6267\u884creplace<\/span><br \/>\n<span style=\"color: #ff0000;\">#\u5982\u679c\u4e0d\u5b58\u5728\u6267\u884ccreate<\/span><br \/>\nCREATE OR REPLACE VIEW demo<br \/>\nAS<br \/>\nSELECT*FROM emp<\/p>\n<p><span style=\"color: #ff0000;\">#\u7eaf\u4fee\u6539<\/span><br \/>\nALTER VIEW demo AS SELECT*FROM dept<\/p>\n<p><span style=\"color: #ff0000;\">#\u5220\u9664\u89c6\u56fe<\/span><br \/>\nDROP VIEW demo,test<\/p>\n","protected":false},"excerpt":{"rendered":"<p>2020Javaweb\u6559\u7a0b\u4e4bmysql\u6570\u636e\u5e93\u4e8b\u52a1\u4ee5\u53ca\u89c6\u56fe \u4e8b\u52a1\u6982\u8ff0 \u200b \u4e00\u7ec4\u8981\u4e48\u540c\u65f6\u6267\u884c\u6210\u529f\uff0c\u8981\u4e48\u540c\u65f6\u5931\u8d25\u7684S [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-2359","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2359","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2359"}],"version-history":[{"count":2,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2359\/revisions"}],"predecessor-version":[{"id":2361,"href":"https:\/\/www.9713job.com\/index.php?rest_route=\/wp\/v2\/posts\/2359\/revisions\/2361"}],"wp:attachment":[{"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.9713job.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}