1. MySQLãšã¯ïŒ
1.1 ããŒã¿ããŒã¹ãšã¯
ããŒã¿ããŒã¹ãšã¯ãæ§ã ãªããŒã¿ãäžå çã«ç®¡çã»ä¿åããããã®ã·ã¹ãã ã§ããããŒã¿ããŒã¹ã¯ãæ å ±ãæŽçããæ€çŽ¢ãæŽæ°ãè¡ãããšã容æã«ããŸããäŸãã°ãå³æžé€šã®æ¬ã®ãªã¹ãããåŠæ ¡ã®çåŸã®æ瞟衚ãªã©ãæ¥åžžç掻ã«ãããæ§ã ãªæ å ±ã¯ããŒã¿ããŒã¹ãçšããŠç®¡çãããŠããŸãã
ããŒã¿ããŒã¹ã¯ãæ å ±ãäžå€®ã«éçŽããããããããŒã¿ã®éè€ãççŸãé²ãããšãã§ããŸãããŸããç¹å®ã®æ å ±ãè¿ éã«åãåºããããæ å ±ãè¿œå ããããæ¢åã®æ å ±ãæŽæ°ãããããããšãå¯èœã§ãã
äžè¬çã«ãããŒã¿ããŒã¹ã¯ããŒãã«ãšåŒã°ããæ§é ãçšããŠããŒã¿ãä¿åããŸãããããã®ããŒãã«ã¯è¡ãšåã§æ§æãããããããã®è¡ã¯åã ã®ããŒã¿ã¬ã³ãŒãïŒäŸãã°ãäžäººã®ãŠãŒã¶ãŒãäžã€ã®è£œåïŒãè¡šããåã¯ãã®ã¬ã³ãŒãã®ç¹æ§ïŒäŸãã°ããŠãŒã¶ãŒã®ååã補åã®äŸ¡æ ŒïŒãè¡šããŸãã
以äžã«ç°¡åãªããŒã¿ããŒã¹ã®ããŒãã«ã®äŸã瀺ããŸãã
åå | 幎霢 | äœæ |
---|---|---|
å±±ç°å€ªé | 20 | æ±äº¬éœæ°å®¿åº |
äœè€è±å | 22 | 倧éªåžååº |
ãã®ããŒãã«ã§ã¯ãåè¡ãäžäººã®äººç©ãè¡šããååããã®äººç©ã®ç¹æ§ã瀺ããŠããŸããããã¯ãããŒã¿ããŒã¹ãããŒã¿ãæŽçããåãæ±ãã容æã«ããäžäŸã§ãã
1.2 ããŒã¿ããŒã¹ã®çš®é¡
ããŒã¿ããŒã¹ã«ã¯æ§ã ãªçš®é¡ãããããããããç¹å®ã®çšéã«æé©åãããŠããŸãã以äžã«ãäž»ãªããŒã¿ããŒã¹ã®çš®é¡ãããã€ã玹ä»ããŸãã
ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ïŒRDBMSïŒ:
ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã¯ãããŒã¿ãäºãã«é¢é£ä»ããããããŒãã«åœ¢åŒã§æ ŒçŽããŸããããããã®ããŒãã«ã¯è¡ïŒã¬ã³ãŒãïŒãšåïŒãã£ãŒã«ãïŒã§æ§æãããäžæã®ããŒã«ãã£ãŠé¢é£ä»ããããŠããŸããããã«ãããããŒã¿ã®æ€çŽ¢ãçµåã容æã«ãªããŸããSQLïŒStructured Query LanguageïŒãšããèšèªãããã®çš®ã®ããŒã¿ããŒã¹ãšã®ã€ã³ã¿ã©ã¯ã·ã§ã³ã«åºã䜿çšãããŠããŸããMySQLã¯ãã®çš®é¡ã®ããŒã¿ããŒã¹ã®äžã€ã§ãã
ãã³ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ïŒNoSQLïŒ:
ãã³ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã¯ããªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ãšã¯ç°ãªãããŒã¿ã¢ãã«ã䜿çšããŸãããããã®ããŒã¿ããŒã¹ã¯ãã¹ã±ãŒã©ããªãã£ãšæè»æ§ãéèŠããJSONã®ãããªåœ¢åŒã§ããŒã¿ãä¿åããŸããäž»ãªã¿ã€ãã«ã¯ããã¥ã¡ã³ããããŒããªã¥ãŒãã«ã©ã ãã°ã©ãããããŸããMongoDBãCassandraããã®çš®é¡ã«å±ããŸãã
ãªããžã§ã¯ãæåããŒã¿ããŒã¹ïŒOODBMSïŒ:
ãªããžã§ã¯ãæåããŒã¿ããŒã¹ã¯ãããŒã¿ããªããžã§ã¯ããšããŠä¿åããŸãããããã®ãªããžã§ã¯ãã¯ãããèªäœãããŒã¿ãšã¡ãœããïŒãã®ããŒã¿ã«å¯ŸããæäœïŒãæã€ããšãã§ããŸãããã®çš®é¡ã®ããŒã¿ããŒã¹ã¯ãè€éãªããŒã¿æ§é ãæã€ã¢ããªã±ãŒã·ã§ã³ã«é©ããŠããŸãã
åæ£ããŒã¿ããŒã¹:
åæ£ããŒã¿ããŒã¹ã¯ãç©ççã«åé¢ãããè€æ°ã®å Žæã«ããŒã¿ãæ ŒçŽããŸãããäžã€ã®ããŒã¿ããŒã¹ãšããŠåäœããŸããããã«ãããããŒã¿ã®åé·æ§ãšå¯çšæ§ãåäžããŸãã
ããããã®ããŒã¿ããŒã¹ã®çš®é¡ã¯ããã®ç¹æ§ã«ãã£ãŠç°ãªãå©ç¹ãšæ¬ ç¹ãæã¡ãŸãããã®ãããç¹å®ã®ã¢ããªã±ãŒã·ã§ã³ãããžãã¹ããŒãºã«æé©ãªããŒã¿ããŒã¹ã®çš®é¡ãéžæããéã«ã¯ããã®ç¹æ§ãç解ããããšãéèŠã§ãã
äŸãã°ããªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã¯ãããŒã¿ã®æŽåæ§ãç¶æããå¿ èŠããããè€éãªã¯ãšãªãé »ç¹ã«å®è¡ããã¢ããªã±ãŒã·ã§ã³ã«é©ããŠããŸãããããã倧éã®ããŒã¿ãæ±ãå¿ èŠãããå ŽåããããŒã¿æ§é ãé »ç¹ã«å€ããå Žåã«ã¯ãã¹ã±ãŒã©ããªãã£ãæè»æ§ã®èŠ³ç¹ãããã³ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ãé©ããŠããããšããããŸãã
äžæ¹ããªããžã§ã¯ãæåããŒã¿ããŒã¹ã¯ãããŒã¿ãšãã®æäœãäžç·ã«æ±ãããšãå¯èœãªãããè€éãªããŒã¿æ§é ãæã€ã¢ããªã±ãŒã·ã§ã³ã«é©ããŠããŸãããããããããã®ããŒã¿ããŒã¹ã¯ãäžè¬çã«ã¯ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ããã³ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã»ã©åºã䜿çšãããŠããŸããã
æåŸã«ãåæ£ããŒã¿ããŒã¹ã¯ãããŒã¿ã®åé·æ§ãšå¯çšæ§ãæäŸããããšãã§ããŸãããããã«ã¯ããŒã¿ã®äžè²«æ§ãç¶æããããã®è¿œå ã®åŽåãå¿ èŠã«ãªãããšããããŸãã
ãããã®æŠå¿µãç解ããããšã§ãåããŒã¿ããŒã¹ã®çš®é¡ãã©ã®ãããªç®çãç¶æ³ã«æé©ãªã®ããå€æããããšãã§ããŸãããããŠããã®ç¥èãåºã«ããŠã次ã®ã»ã¯ã·ã§ã³ã§ã¯MySQLã«ã€ããŠè©³ããèŠãŠãããŸãããã
1.3 MySQLã®å®çŸ©ãšç¹åŸŽ
MySQLãšã¯ããªãŒãã³ãœãŒã¹ã®ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ç®¡çã·ã¹ãã ïŒRDBMSïŒã®äžã€ã§ãç¹ã«ãŠã§ãã¢ããªã±ãŒã·ã§ã³ã®éçºã«åºã䜿ãããŠããŸãããªãŒãã³ãœãŒã¹ãšã¯ããã®ãœãããŠã§ã¢ã®ãœãŒã¹ã³ãŒããå ¬éããã誰ã§ãèªç±ã«äœ¿çšãä¿®æ£ãé åžããããšãã§ãããšããæå³ã§ãã
MySQLã¯ãã®ããã©ãŒãã³ã¹ãä¿¡é Œæ§ããããŠäœ¿ããããããå€ãã®éçºè ã«éžã°ããŠããŸãããŸãããªãŒãã³ãœãŒã¹ã§ãããããå¿ èŠã«å¿ããŠã«ã¹ã¿ãã€ãºããããšãå¯èœã§ããããã®ã³ãã¥ããã£ããã®ãµããŒãã掻çºã§ãã
以äžã«ãMySQLã®äž»ãªç¹åŸŽãããã€ã玹ä»ããŸãã
1. é«éæ§: MySQLã¯ããã®èšèšãèªã¿åãã«æé©åãããŠãããããé«éãªããã©ãŒãã³ã¹ãçºæ®ããŸããããã¯ããŠã§ããµã€ãããªã³ã©ã€ã³ã¢ããªã±ãŒã·ã§ã³ããŠãŒã¶ãŒã®ã¯ãšãªã«è¿ éã«å¿çããããšãå¯èœã«ããŸãã
2. ã¹ã±ãŒã©ããªãã£: MySQLã¯ãå°èŠæš¡ãªã¢ããªã±ãŒã·ã§ã³ãã倧èŠæš¡ãªãšã³ã¿ãŒãã©ã€ãºã·ã¹ãã ãŸã§ãæ§ã ãªèŠæš¡ã®ãããžã§ã¯ãã«å¯Ÿå¿ããããšãã§ããŸããå¿ èŠã«å¿ããŠããŒããŠã§ã¢ãªãœãŒã¹ãè¿œå ããããšã§ãããŒã¿ããŒã¹ã®å®¹éãã¹ã±ãŒã«ã¢ããããããšãå¯èœã§ãã
3. ã»ãã¥ãªãã£: MySQLã¯ãå ç¢ãªã»ãã¥ãªãã£æ©èœãåããŠããŸãããã¹ã¯ãŒãä¿è·ããããã¯ãŒã¯ã¢ã¯ã»ã¹å¶åŸ¡ãæå·åãªã©ã®æ©èœãéããŠãããŒã¿ã®å®å šæ§ãšãã©ã€ãã·ãŒãä¿ã€ããšãã§ããŸãã
4. ã¬ããªã±ãŒã·ã§ã³: MySQLã¯ãããŒã¿ã®ã¬ããªã±ãŒã·ã§ã³ïŒè€è£œïŒããµããŒãããŠããŸããããã«ãããããŒã¿ã®ããã¯ã¢ããããè² è·åæ£ããã§ã€ã«ãªãŒããŒã®å¯Ÿçã容æã«ãªããŸãã
5. ãµããŒã: MySQLã¯ãäžçäžã®å€§ããªã³ãã¥ããã£ã«æ¯ããããŠãããåé¡ãçºçããå Žåã®ãµããŒããå å®ããŠããŸãããŸããåçšã©ã€ã»ã³ã¹ãè³Œå ¥ããããšã§ãå°éçãªæè¡ãµããŒããåããããšãå¯èœã§ãã
ãããã®ç¹æ§ãçµã¿åãããããšã§ãMySQLã¯ãŠã§ãã¢ããªã±ãŒã·ã§ã³ãäžå¿ã«ãå€çš®å€æ§ãªçšéã§äœ¿çšãããŠããŸãããŸããPHPãJavaãPythonãªã©ã®å€ãã®ããã°ã©ãã³ã°èšèªãã容æã«ã¢ã¯ã»ã¹ã§ããApacheãNginxãªã©ã®ãŠã§ããµãŒããšã®é£æºã容æãªããããŠã§ãéçºã®çŸå Žã§ããèŠãããæè¡ã¹ã¿ãã¯ã®äžéšãšãªã£ãŠããŸãã
ãããã®ç¹åŸŽãç解ããããšã§ãMySQLãã©ã®ãããªå Žé¢ã§é©ããŠããã®ãããŸãã©ã®ããã«æŽ»çšã§ããã®ããèŠããŠããã¯ãã§ãã次ã®ã»ã¯ã·ã§ã³ã§ã¯ãæŽã«å ·äœçãªå©çšã·ãŒã³ãšMySQLã®äœ¿çšæ¹æ³ã«ã€ããŠæãäžããŠãããŸãããã
2. MySQLã®éèŠãªã³ã³ããŒãã³ã
2.1 ããŒãã«
ããŒã¿ããŒã¹ãæ§æããéèŠãªèŠçŽ ã®äžã€ããããŒãã«ãã§ããããŒãã«ãšã¯ãããŒã¿ãæŽçããŠæ ŒçŽããããã®æ§é ã§ãåè¡ãšåã«ãã£ãŠæ§æãããŸããããŒã¿ã管çããŸãã
ããŒãã«ã®æŠå¿µãç解ããããã«ãã·ã³ãã«ãªäŸãèããŠã¿ãŸããããããšãã°ãåŠçã®æ å ±ã管çããããã®ããŒãã«ãäœæããŸãããã®ããŒãã«ã¯ãååŠçïŒè¡ïŒãšãã®å±æ§ïŒåïŒããããã£ãšã¯ãåŠçã®ååãåŠç±çªå·ãå°æ»ãªã©ã®æ å ±ãç¡èŠããŸãã
ãã®ããã«ãããŒãã«ã¯æ å ±ãæŽçããã¢ã¯ã»ã¹ããããããããã®éèŠãªããŒã«ã«ãªããŸããããããã®ããŒãã«ã¯äžã€ã®ããšã³ãã£ãã£ããè¡šçŸããããããã®è¡ã¯ãã®ãšã³ãã£ãã£ã®äžäŸïŒã€ã³ã¹ã¿ã³ã¹ïŒãè¡šããŸãååã¯ãã®ãšã³ãã£ãã£ã®ç¹å®ã®ç¹æ§ïŒããããã£ïŒãè¡šããŸãã
ãŸããããŒãã«éã§è¡ãããšãè¡ãããšãå¯èœã§ããããããªã¬ãŒã·ã§ã³ããšãããŸããããã«ãããç°ãªãããŒãã«ã®ããŒã¿ãäžç·ã«æ±ãããšãã§ããŸããäŸãã°ãåŠçããŒãã«ãšã³ãŒã¹ããŒãã«ãäºåã«è¡ãããšã§ãç¹å®ã®åŠçãã©ã®ã³ãŒã¹ãåè¬ããŠããã®ããææ¡ããããšãã§ããŸãã
2.2 ãã£ãŒã«ããšã¬ã³ãŒã
ããŒã¿ããŒã¹ã®ããŒãã«ãæ§æããèŠçŽ ã«ã¯ãããã£ãŒã«ãããšãã¬ã³ãŒããããããŸãããããã¯ãããŒã¿ãæŽçããå¹ççã«ã¢ã¯ã»ã¹ã§ããããã«ããããã«éèŠã§ããããã§ã¯ããã£ãŒã«ããšã¬ã³ãŒãã«ã€ããŠè©³ããèŠãŠãããŸãããã
ãã£ãŒã«ã
ãã£ãŒã«ããšã¯ãããŒãã«ã®åã«çžåœããéšåã§ããšã³ãã£ãã£ã®ç¹å®ã®å±æ§ãè¡šçŸããŸããäŸãã°ãåŠçã®æ
å ±ã管çããããŒãã«ã§ã¯ããååãããåŠç±çªå·ãããå°æ»ããªã©ããã£ãŒã«ããšãªããŸãããã£ãŒã«ãã¯ããŒã¿åïŒæååãæ°å€ãæ¥ä»ãªã©ïŒãæã¡ããã®ããŒã¿åã«å¿ããŠããŒã¿ãæ ŒçŽãããŸãã
ã¬ã³ãŒã
ã¬ã³ãŒãã¯ãããŒãã«ã®è¡ã«çžåœããéšåã§ããšã³ãã£ãã£ã®ã€ã³ã¹ã¿ã³ã¹ãè¡šçŸããŸããã€ãŸããåã¬ã³ãŒãã¯ããã®ãšã³ãã£ãã£ã«é¢ãã1ã€ã®ããŒã¿ã»ããã§ããåŠçã®æ
å ±ã管çããããŒãã«ã§ã¯ãååŠçã1ã€ã®ã¬ã³ãŒãã«ãªããŸãã
äŸãã°ã以äžã®ãããªããŒãã«ããããšããŸãã
åŠç±çªå· | åå | å°æ» |
---|---|---|
1001 | å±±ç°å€ªé | æ å ±ç§åŠ |
1002 | éŽæšè±å | çµæžåŠ |
ãã®ããŒãã«ã§ã¯ããåŠç±çªå·ãããååãããå°æ»ãããã£ãŒã«ãã§ãããå±±ç°å€ªéãããšéŽæšè±åããã®æ å ±ãããããã¬ã³ãŒããšããŠæ ŒçŽãããŠããŸãã
ãã£ãŒã«ããšã¬ã³ãŒãã®æŠå¿µãç解ããããšã§ãããŒã¿ããŒã¹å ã®ããŒã¿ã®æŽçãæ€çŽ¢ã容æã«ãªããŸãããŸãããããã®æŠå¿µãåºã«ãããŒã¿ããŒã¹ãæäœããSQLïŒStructured Query LanguageïŒãçšããŠãå¹ççã«ããŒã¿ãæœåºããããæŽæ°ãããã§ããããã«ãªããŸãã
2.3 ããŒ
ããŒã¿ããŒã¹ã«ããããããŒãã¯ãããŒãã«ã®äžããç¹å®ã®ã¬ã³ãŒããäžæã«èå¥ããããç°ãªãããŒãã«éã®é¢ä¿ã確ç«ãããããã®ã«éèŠãªåœ¹å²ãæãããŸããããŒã«ã¯äž»ã«ãäž»ããŒãïŒPrimary KeyïŒãšãå€éšããŒãïŒForeign KeyïŒã®äºã€ã®çš®é¡ããããŸããããããã®ç¹åŸŽãšåœ¹å²ã«ã€ããŠè©³ããèŠãŠãããŸãããã
äž»ããŒ
äž»ããŒãšã¯ãããŒãã«å
ã®åã¬ã³ãŒããäžæã«èå¥ããããã®ãã£ãŒã«ãïŒãŸãã¯ãã£ãŒã«ãã®çµã¿åããïŒã§ããã€ãŸããäž»ããŒã®å€ã¯ããŒãã«å
ã§éè€ããŠã¯ãªããªãããšããã«ãŒã«ããããŸããäž»ããŒã¯ãããŒãã«å
ã®ç¹å®ã®ã¬ã³ãŒããé«éã«æ€çŽ¢ããã®ã«åœ¹ç«ã¡ãŸãã
äŸãã°ãåŠçæ å ±ã管çããããŒãã«ã§ã¯ããåŠç±çªå·ããäž»ããŒã«ãªãããšãå€ãã§ãããªããªããååŠçã«ã¯äžæã®åŠç±çªå·ãä»äžãããããã«ãã£ãŠåŠçãèå¥ã§ããããã§ãã
å€éšããŒ
å€éšããŒãšã¯ãããããŒãã«ã®ãã£ãŒã«ããå¥ã®ããŒãã«ã®äž»ããŒãåç
§ããŠããå Žåããã®ãã£ãŒã«ããæããŸããå€éšããŒã¯ãç°ãªãããŒãã«éã®é¢é£æ§ïŒãªã¬ãŒã·ã§ã³ã·ããïŒãå®çŸ©ããããã«äœ¿çšãããŸãã
äŸãã°ãåŠçããŒãã«ãšã³ãŒã¹ããŒãã«ããããåŠçãã©ã®ã³ãŒã¹ãåè¬ããŠããã®ããèšé²ããããšããŸãããã®å Žåãæ°ãã«ãåŠçã³ãŒã¹ãããŒãã«ãäœæãããã®ããŒãã«ã«ãåŠç±çªå·ããã£ãŒã«ãïŒåŠçããŒãã«ã®äž»ããŒãåç §ïŒãšãã³ãŒã¹IDããã£ãŒã«ãïŒã³ãŒã¹ããŒãã«ã®äž»ããŒãåç §ïŒãèšããããšã§ãåŠçãšã³ãŒã¹ã®éã®é¢é£æ§ãèšé²ã§ããŸãã
ãã®ããã«ãäž»ããŒãšå€éšããŒã¯ãããŒã¿ããŒã¹å ã®ããŒã¿ãå¹ççã«ç®¡çããé¢é£ä»ããããã®éèŠãªããŒã«ã§ãã
2.4 ã€ã³ããã¯ã¹
ããŒã¿ããŒã¹ãæ±ãäžã§ãããŒã¿ã®æ€çŽ¢é床ãåäžãããããã®éèŠãªæŠå¿µããã€ã³ããã¯ã¹ãã§ããæ¬æžæ£ã«æ¬ã䞊ã¹ããšããã¿ã€ãã«ãèè åã§ãœãŒãããŠãããšãç¹å®ã®æ¬ãæ¢ããšãã«äŸ¿å©ã§ããããããŒã¿ããŒã¹ã®ã€ã³ããã¯ã¹ãåããããªåœ¹å²ãæãããŸãã
ã€ã³ããã¯ã¹ãšã¯ãç¹å®ã®ãã£ãŒã«ãïŒåïŒã®ããŒã¿ã«å¯ŸããŠããã®å€ãšãã®å€ãååšããå ŽæïŒã¬ã³ãŒãïŒãšã®å¯Ÿå¿é¢ä¿ããªã¹ãåãããã®ã§ããããã«ãããç¹å®ã®ããŒã¿ãæ¢ãéã«å šãŠã®ã¬ã³ãŒãã調ã¹ãå¿ èŠããªããªããæ€çŽ¢é床ãå€§å¹ ã«åäžãããããšãã§ããŸãã
MySQLã§ã¯ãç¹å®ã®ãã£ãŒã«ãã«å¯ŸããŠã€ã³ããã¯ã¹ãäœæããããšãã§ããŸããã€ã³ããã¯ã¹ãäœæãããã£ãŒã«ããéžã¶éã«ã¯ãæ€çŽ¢æ¡ä»¶ã«ãã䜿ããããã£ãŒã«ããå€ã®çš®é¡ãå€ããäžææ§ãé«ããã£ãŒã«ããé©ããŠããŸããäžæ¹ã§ãå€ã®çš®é¡ãå°ãªããã£ãŒã«ãããæŽæ°ãé »ç¹ã«è¡ããããã£ãŒã«ãã«å¯ŸããŠã€ã³ããã¯ã¹ãäœæãããšãã€ã³ããã¯ã¹èªäœã®æŽæ°ã«æéãããããããéã«ããã©ãŒãã³ã¹ãäœäžããå¯èœæ§ããããŸãã
ãŸããã€ã³ããã¯ã¹ã¯äžã€ã®ããŒãã«ã«å¯ŸããŠè€æ°äœæããããšãå¯èœã§ãããããè€æ°åã€ã³ããã¯ã¹ããŸãã¯ãè€åã€ã³ããã¯ã¹ããšåŒã³ãŸããè€æ°åã€ã³ããã¯ã¹ã¯ãè€æ°ã®ãã£ãŒã«ããçµã¿åãããæ¡ä»¶ã§ã®æ€çŽ¢ãé«éåããŸãã
ããããã€ã³ããã¯ã¹ã¯ããŒã¿ã®æ€çŽ¢é床ãåäžãããäžæ¹ã§ãããŒã¿ã®æŽæ°ïŒæ¿å ¥ãåé€ãæŽæ°ïŒæã«ã¯ã€ã³ããã¯ã¹ã®æŽæ°ãå¿ èŠãšãªããããã«ã¯æéãããããããç¡éã«ã€ã³ããã¯ã¹ãäœæãããšå šäœã®ããã©ãŒãã³ã¹ãäœäžããå¯èœæ§ããããŸãããã®ãããã€ã³ããã¯ã¹ã¯å¿ èŠãªãã£ãŒã«ãã«å¯ŸããŠé©åã«äœæããããšãéèŠã§ãã
以äžãã€ã³ããã¯ã¹ã®åºæ¬çãªæŠå¿µãšãã®åœ¹å²ã§ãã
3. MySQLã®æäœæ¹æ³
3.1 MySQLã®ã€ã³ã¹ããŒã«
ãããŸã§MySQLã«ã€ããŠã®åºæ¬çãªæŠå¿µã説æããŠããŸãããããããã®çè«ãå®éã«æŽ»çšããŠã¿ãããã«ã¯ããŸãèªèº«ã®ããœã³ã³ã«MySQLãã€ã³ã¹ããŒã«ããå¿ èŠããããŸãã以äžã«ãå ·äœçãªã€ã³ã¹ããŒã«æ¹æ³ã解説ããŸãã
ãŸããMySQLãããŠã³ããŒãããããã«ã¯å ¬åŒãŠã§ããµã€ãã蚪ããŸãããŠã§ããµã€ãäžã§ãããŠã³ããŒãããŸãã¯ãGet MySQLãã®ãããªãªã³ã¯ãã¯ãªãã¯ããŸãããããšãæ§ã ãªããŒãžã§ã³ã®MySQLããªã¹ãã¢ãããããããŒãžã«é£ã³ãŸããèªåã®ããœã³ã³ã®ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ïŒWindowsãMacãLinuxãªã©ïŒã«åãããŠé©åãªããŒãžã§ã³ãéžæããããŠã³ããŒããã¯ãªãã¯ããŸãã
ããŠã³ããŒããå®äºããããããŠã³ããŒããããã¡ã€ã«ãéããã€ã³ã¹ããŒã©ãŒã®æ瀺ã«åŸã£ãŠã€ã³ã¹ããŒã«ãé²ããŠãããŸãããã®éããŠãŒã¶ãŒåããã¹ã¯ãŒããã»ãã¥ãªãã£èšå®ãªã©ãèšå®ããããšã«ãªããŸããããããã¯åŸã§MySQLã«ã¢ã¯ã»ã¹ããéã«å¿ èŠãšãªãæ å ±ãªã®ã§ãå¿ããã«ã¡ã¢ããŠãããŸãããã
ãŸããã€ã³ã¹ããŒã«äžã«ã¯MySQLã®ããŒã¿ããŒã¹ãšã³ãžã³ã ãã§ãªãããMySQL WorkbenchãããMySQL Shellããªã©ã®è£å©ããŒã«ãäžç·ã«ã€ã³ã¹ããŒã«ããããšãæšå¥šããŸãããããã®ããŒã«ã¯ãMySQLã®æäœãã°ã©ãã£ã«ã«ã«è¡ã£ãããã³ãã³ãã©ã€ã³ããæäœãããããããã®ãã®ã§ãããŒã¿ããŒã¹ã®ç®¡çãå¹ççã«è¡ãããã«ã¯å€§å€åœ¹ç«ã¡ãŸãã
ã€ã³ã¹ããŒã«ãå®äºããããMySQLãæ£ããåäœãããã確èªããŸããããéåžžã¯ãMySQL WorkbenchããéããŠãLocal instanceããããã«ã¯ãªãã¯ããããšã§ãå ã»ã©èšå®ãããŠãŒã¶ãŒåãšãã¹ã¯ãŒããå ¥åããŠMySQLã«æ¥ç¶ã§ããŸããããã§ãšã©ãŒãåºãªããã°ãç¡äºã«MySQLã®ã€ã³ã¹ããŒã«ã¯å®äºã§ãã
以äžãMySQLã®ã€ã³ã¹ããŒã«æ¹æ³ã«ãªããŸãã
3.2 ããŒã¿ããŒã¹ã®äœæãšéžæ
MySQLãã€ã³ã¹ããŒã«ããåŸã次ã«è¡ãã¹ãããšã¯ãæ°ããªããŒã¿ããŒã¹ã®äœæã§ããããŒã¿ããŒã¹ã¯æ å ±ãæŽçããæ ŒçŽããããã®å®¹åšã®ãããªãã®ã§ããããããç¬ç«ããŠäœåããŸããããŒã¿ããŒã¹ãäœæããããšã§ãããªãã®ããŒã¿ãä¿ç®¡ããæäœããããšãå¯èœã«ãªããŸãã
ããŒã¿ããŒã¹ãäœæããã«ã¯ã以äžã®ãããªSQLã³ãã³ãã䜿ããŸãïŒ
CREATE DATABASE ããŒã¿ããŒã¹å;
ããã§ããããŒã¿ããŒã¹åãã®éšåã«ã¯ä»»æã®ååãå ¥ããŠãã ããããã®ååããã®åŸã®æäœã§ããŒã¿ããŒã¹ãæå®ããéã«äœ¿ãããŸãã
ããŒã¿ããŒã¹ãäœæãããããã®ããŒã¿ããŒã¹ãéžæããŠæäœå¯Ÿè±¡ãšããå¿ èŠããããŸããããã«ã¯ä»¥äžã®ãããªSQLã³ãã³ãã䜿ããŸãïŒ
USE ããŒã¿ããŒã¹å;
ããã§ãããããŒã¿ããŒã¹åãã®éšåã«ã¯å ã»ã©äœæããããŒã¿ããŒã¹ã®ååãå ¥ããŠãã ãããããã§ããã®ããŒã¿ããŒã¹ãéžæããããã®åŸã®æäœïŒããŒãã«ã®äœæãããŒã¿ã®æ¿å ¥ãªã©ïŒã¯ãã¹ãŠãã®ããŒã¿ããŒã¹å ã§è¡ãããããšã«ãªããŸãã
以äžã®ããã«ãMySQLã§ã¯ããŒã¿ããŒã¹ã®äœæãšéžæãSQLã³ãã³ããéããŠè¡ããŸããSQLã³ãã³ãã¯ããŒã¿ããŒã¹æäœã®åºæ¬ãšãªãããŒã«ã§ããããç解ã䜿ãããªãããšãããŒã¿ããŒã¹ç®¡çã®éµãšãªããŸãã
3.3 ããŒãã«ã®äœæãšæäœ
ããŒã¿ããŒã¹ãäœæãããéžæãããåŸã次ã®ã¹ãããã¯ããŒãã«ã®äœæã§ããããŒãã«ã¯ããŒã¿ããŒã¹å ã®ããŒã¿ãæ§é åããŠä¿åããããã®ãã®ã§ãè¡ïŒã¬ã³ãŒãïŒãšåïŒãã£ãŒã«ãïŒã§æ§æãããŠããŸããããããã®ãã£ãŒã«ãã¯ç¹å®ã®ããŒã¿åïŒæ°å€ãæååãæ¥ä»ãªã©ïŒãæã¡ãŸãã
MySQLã§ã¯ãããŒãã«ã®äœæ㯔CREATE TABLE”ã³ãã³ãã䜿çšããŠè¡ããŸãã以äžã«ãã·ã³ãã«ãªããŒãã«äœæã®SQLã³ãã³ãã®äŸã瀺ããŸãïŒ
CREATE TABLE ããŒãã«å (
ãã£ãŒã«ãå1 ããŒã¿å,
ãã£ãŒã«ãå2 ããŒã¿å,
...
);
ããã§ããããŒãã«åãã¯ä»»æã®ååãããã£ãŒã«ãåãã¯åã®ååãããããŒã¿åãã¯ãã®åã®ããŒã¿åãæå®ããŸããäŸãã°ãååãšå¹Žéœ¢ãä¿åããããŒãã«ãäœæããå Žåã以äžã®ããã«ãªããŸãïŒ
CREATE TABLE People (
Name VARCHAR(100),
Age INT
);
ããŒãã«ãäœæãããããããŒã¿ãæ¿å ¥ããããšãã§ããŸããããŒã¿ã®æ¿å ¥ã¯”INSERT INTO”ã³ãã³ãã䜿çšããŠè¡ããŸãã以äžã«ãããŒã¿æ¿å ¥ã®SQLã³ãã³ãã®äŸã瀺ããŸãïŒ
INSERT INTO ããŒãã«å (ãã£ãŒã«ãå1, ãã£ãŒã«ãå2, ...) VALUES (å€1, å€2, ...);
äžèšã®”People”ããŒãã«ã«ããŒã¿ãæ¿å ¥ããäŸã¯æ¬¡ã®ããã«ãªããŸãïŒ
INSERT INTO People (Name, Age) VALUES ('John Doe', 30);
ãããã®åºæ¬çãªSQLã³ãã³ããçšããŠãMySQLããŒã¿ããŒã¹å ã«ããŒãã«ãäœæããããŒã¿ãæ¿å ¥ããããšãã§ããŸãã
3.4 ããŒã¿ã®æ¿å ¥ãæŽæ°ãåé€
ããŒã¿ããŒã¹ããŒãã«ã«ããŒã¿ãè¿œå ãä¿®æ£ãåé€ããã«ã¯ãããããINSERTãUPDATEãããã³DELETE SQLã³ãã³ãã䜿çšããŸãã
ããŒã¿ã®æ¿å ¥
ãã§ã«åã®ã»ã¯ã·ã§ã³ã§è§Šããããã«ãããŒã¿ã®æ¿å ¥ã¯”INSERT INTO”ã³ãã³ãã䜿çšããŠè¡ããŸãã以äžã«ãããŒã¿æ¿å ¥ã®SQLã³ãã³ãã®äŸãå床瀺ããŸãïŒ
INSERT INTO ããŒãã«å (ãã£ãŒã«ãå1, ãã£ãŒã«ãå2, ...) VALUES (å€1, å€2, ...);
ããŒã¿ã®æŽæ°
ããŒã¿ããŒã¹ããŒãã«å ã®æ¢åã®ããŒã¿ãå€æŽããã«ã¯ã”UPDATE”ã³ãã³ãã䜿çšããŸãã”UPDATE”ã³ãã³ãã¯ä»¥äžã®åœ¢åŒãæã¡ãŸãïŒ
UPDATE ããŒãã«å SET ãã£ãŒã«ãå1 = æ°ããå€1, ãã£ãŒã«ãå2 = æ°ããå€2, ... WHERE æ¡ä»¶;
“WHERE”å¥ã¯æŽæ°ããã¬ã³ãŒããç¹å®ããããã®ãã®ã§ãããã®å¥ããªããšãæå®ãããã£ãŒã«ãã®å šã¬ã³ãŒããæŽæ°ãããŠããŸããŸããäŸãã°ã”People”ããŒãã«ã®”John Doe”ã®å¹Žéœ¢ã31ã«æŽæ°ããã«ã¯ã次ã®ããã«ããŸãïŒ
UPDATE People SET Age = 31 WHERE Name = 'John Doe';
ããŒã¿ã®åé€
ããŒã¿ããŒã¹ããŒãã«ããããŒã¿ãåé€ããã«ã¯ã”DELETE”ã³ãã³ãã䜿çšããŸãã”DELETE”ã³ãã³ãã¯ä»¥äžã®åœ¢åŒãæã¡ãŸãïŒ
DELETE FROM ããŒãã«å WHERE æ¡ä»¶;
“WHERE”å¥ã¯åé€ããã¬ã³ãŒããç¹å®ããããã®ãã®ã§ãããã®å¥ããªããšãå šã¬ã³ãŒããåé€ãããŠããŸããŸãã®ã§æ³šæãå¿ èŠã§ããäŸãã°ã”People”ããŒãã«ãã”John Doe”ã®ã¬ã³ãŒããåé€ããã«ã¯ã次ã®ããã«ããŸãïŒ
DELETE FROM People WHERE Name = 'John Doe';
ãããã®åºæ¬çãªSQLã³ãã³ããçšããŠãMySQLããŒã¿ããŒã¹å ã®ããŒãã«ã§ããŒã¿ãæ¿å ¥ãæŽæ°ãåé€ããããšãã§ããŸãã
4. SQLãšã¯ïŒ
4.1 SQLã®æŠèŠ
ããŒã¿ããŒã¹ãå¹ççã«æäœããããã«ã¯ãSQLïŒStructured Query LanguageïŒã®ç解ãæ¬ ãããŸãããSQLã¯ããŒã¿ããŒã¹ã«å¯ŸããããŸããŸãªæäœãå¯èœã«ããèšèªã§ãããŒã¿ã®æ¿å ¥ãæŽæ°ãåé€ããæ€çŽ¢ã«è³ããŸã§ãå¹ åºãæ©èœãæäŸããŠããŸãã
SQLã¯ãã®ååã瀺ãéããæ§é åãããåãåããïŒã¯ãšãªïŒãè¡ãããã®èšèªã§ããSQLã®ã³ãã³ãã䜿çšããã°ãå¿ èŠãªæ å ±ã ããç¹å®ã®åœ¢åŒã§ååŸããããããŒã¿ããŒã¹ã®æ§é ãå€æŽããããæ°ããªããŒã¿ãä¿åãããããããšãå¯èœã«ãªããŸãã
SQLã¯å€§ããåããŠ4ã€ã®ã«ããŽãªãŒã«åé¡ãããŸãããããã¯ãããŒã¿æäœèšèªãããããŒã¿å®çŸ©èšèªãããããŒã¿å¶åŸ¡èšèªããããã©ã³ã¶ã¯ã·ã§ã³å¶åŸ¡èšèªãã§ãã
- ããŒã¿æäœèšèª (DML): ããŒã¿ã®æ€çŽ¢ãæ¿å ¥ãæŽæ°ãåé€ãªã©ãããŒã¿ãã®ãã®ãæäœããããã®åœä»€ãå«ã¿ãŸããå ·äœçã«ã¯SELECTãINSERTãUPDATEãDELETEãªã©ã®ã³ãã³ãããããŸãã
- ããŒã¿å®çŸ©èšèª (DDL): ããŒã¿ããŒã¹ã®æ§é ãå®çŸ©ããããã®åœä»€ãå«ã¿ãŸããå ·äœçã«ã¯CREATEãDROPãALTERãªã©ã®ã³ãã³ãããããŸãã
- ããŒã¿å¶åŸ¡èšèª (DCL): ããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹æš©ãå¶åŸ¡ããããã®åœä»€ãå«ã¿ãŸããå ·äœçã«ã¯GRANTãREVOKEãªã©ã®ã³ãã³ãããããŸãã
- ãã©ã³ã¶ã¯ã·ã§ã³å¶åŸ¡èšèª (TCL): ããŒã¿ã®äžè²«æ§ãä¿ã€ããã®åœä»€ãå«ã¿ãŸããå ·äœçã«ã¯COMMITãROLLBACKãªã©ã®ã³ãã³ãããããŸãã
ãããã®ååœä»€ãçµã¿åãããŠäœ¿çšããããšã§ãããŒã¿ããŒã¹äžã§é«åºŠãªæäœãè¡ãããšãã§ããŸãããŸããSQLã¯ãã®æ§æã人éãç解ããããèªç¶èšèªã«è¿ã圢ã§èšèšãããŠãããããåŠç¿ãããããšãããŠããŸãã
4.2 SQLã®çš®é¡
SQLã¯ãã®ç¹æ§ãšäœ¿ãããå Žé¢ã«ãã£ãŠãããã€ãã®çš®é¡ã«åããããŸãããããããç¹å®ã®ç®çã®ããã«èšèšãããŠãããããŒã¿ããŒã¹ãšã®çžäºäœçšãããå¹æçã«è¡ãããã«åœ¹ç«ã¡ãŸãã
äž»ã«3ã€ã®SQLã¿ã€ãããããŸã: DDLïŒããŒã¿å®çŸ©èšèªïŒãDMLïŒããŒã¿æäœèšèªïŒãããã³DCLïŒããŒã¿å¶åŸ¡èšèªïŒã§ãã
DDLïŒããŒã¿å®çŸ©èšèªïŒ
DDLã¯ããŒã¿ããŒã¹ã®æ§é ãå®çŸ©ããããã®SQLã§ããå ·äœçã«ã¯ãããŒãã«ãã€ã³ããã¯ã¹ã®äœæãå€æŽãåé€ãªã©ã®æäœãè¡ããŸããDDLã®äž»èŠãªã³ãã³ãã«ã¯CREATEãALTERãDROPãå«ãŸããŸãã
DMLïŒããŒã¿æäœèšèªïŒ
DMLã¯ããŒã¿ãã®ãã®ãæäœããããã®SQLã§ããããã«ã¯ã¬ã³ãŒãã®æ¿å ¥ãæŽæ°ãåé€ãããã³æ€çŽ¢ãªã©ã®æäœãå«ãŸããŸããDMLã®äž»èŠãªã³ãã³ãã«ã¯SELECTãINSERTãUPDATEãDELETEãå«ãŸããŸãã
DCLïŒããŒã¿å¶åŸ¡èšèªïŒ
DCLã¯ããŒã¿ããŒã¹ã®ã»ãã¥ãªãã£ãæŽåæ§ãå¶åŸ¡ããããã®SQLã§ããããã«ã¯ãŠãŒã¶ãŒã®æš©éãä»äžããããåãæ¶ãããããæäœãå«ãŸããŸããDCLã®äž»èŠãªã³ãã³ãã«ã¯GRANTãšREVOKEãå«ãŸããŸãã
ãããã®SQLã®çš®é¡ã¯ããããããé©çšãããç¹å®ã®ç¶æ³ãšç®çãæã£ãŠããŸããããããã®ã¿ã€ããç解ããé©åãªå Žé¢ã§äœ¿çšããããšããããŒã¿ããŒã¹ãå¹æçã«æäœããããã®éµãšãªããŸãã
4.3 SQLã®åºæ¬çãªææ³
SQLã®åºæ¬çãªææ³ãç解ããããšã¯ãããŒã¿ããŒã¹ãšå¹ççã«ã³ãã¥ãã±ãŒãããããã®ç¬¬äžæ©ã§ããããã§ã¯ãSQLã䜿ã£ãŠããŒã¿ããŒã¹ãšå¯Ÿè©±ããããã®åºæ¬çãªææ³ã«ã€ããŠèª¬æããŸãã
SELECTæ
SELECTæã¯ãããŒã¿ããŒã¹ããããŒã¿ãååŸããããã®åºæ¬çãªã³ãã³ãã§ãã以äžã¯ãã®åºæ¬åœ¢ã§ãã
SELECT column_name FROM table_name;
ããã§ãcolumn_nameã¯ååŸãããã«ã©ã ã®ååããtable_nameã¯ãã®ã«ã©ã ãååšããããŒãã«ã®ååãæå®ããŸããè€æ°ã®ã«ã©ã ãååŸããå Žåã¯ã«ã³ãã§åºåããŸããå šãŠã®ã«ã©ã ãååŸããå Žåã¯ãcolumn_nameã®ä»£ããã«ã¢ã¹ã¿ãªã¹ã¯ (*) ã䜿çšããŸãã
WHEREå¥
WHEREå¥ã¯ãç¹å®ã®æ¡ä»¶ãæºããã¬ã³ãŒãã®ã¿ãååŸããããã«äœ¿çšãããŸãã以äžã¯ãã®åºæ¬åœ¢ã§ãã
SELECT column_name FROM table_name WHERE condition;
ããã§ãconditionã¯ååŸãããã¬ã³ãŒããæºããã¹ãæ¡ä»¶ãæå®ããŸããäŸãã°ã’age > 20′ ãšãã£ãå ·äœçãªæ¡ä»¶ãæå®ããããšãã§ããŸãã
INSERT INTOæ
INSERT INTOæã¯ãããŒãã«ã«æ°ããªã¬ã³ãŒããè¿œå ããããã®ã³ãã³ãã§ãã以äžã¯ãã®åºæ¬åœ¢ã§ãã
INSERT INTO table_name (column1, column2, ...) VALUES (value1, value2, ...);
ããã§ãcolumn1, column2, …ã¯è¿œå ãããããŒã¿ã®ã«ã©ã ã®ååããvalue1, value2, …ã¯ããããã®ã«ã©ã ã«è¿œå ãããå€ãæå®ããŸãã
ãããã®åºæ¬çãªææ³ãç解ããé©åã«å©çšããããšã§ãããŒã¿ããŒã¹ãšã®å¯Ÿè©±ãã¹ã ãŒãºã«é²ããããšãã§ããŸãã
5. SQLãçšããMySQLã®æäœ
5.1 SELECTæã®äœ¿çš
SELECTæã¯ãããŒã¿ããŒã¹ããæ å ±ãåãåºãããã®äž»èŠãªSQLã³ãã³ãã§ãããã®ã»ã¯ã·ã§ã³ã§ã¯ããã®éèŠãªã³ãã³ãã®å ·äœçãªäœ¿çšæ¹æ³ã«ã€ããŠè©³ãã説æããŸãã
åºæ¬çãªSELECTæã®åœ¢åŒã¯æ¬¡ã®éãã§ã:
SELECT column_name FROM table_name;
ããã¯ã”table_name”ãšããããŒãã«ãã”column_name”ãšããåã®ãã¹ãŠã®ããŒã¿ãéžæããããšãæå³ããŸããäŸãã°ã”users”ããŒãã«ãã”username”åã®ãã¹ãŠã®ããŒã¿ãååŸãããå Žåã次ã®ããã«èšè¿°ããŸã:
SELECT username FROM users;
ãŸããã¢ã¹ã¿ãªã¹ã¯ (*) ã䜿çšãããšãããŒãã«ã®ãã¹ãŠã®åãéžæã§ããŸããããã¯ç¹å®ã®ããŒãã«ã®ãã¹ãŠã®ããŒã¿ãååŸããéã«åœ¹ç«ã¡ãŸãããã®äœ¿çšäŸã¯ä»¥äžã®éãã§ã:
SELECT * FROM users;
ãã㯔users”ããŒãã«ã®å šãŠã®åã®ããŒã¿ãååŸããŸãã
å ããŠãSELECTæã¯ãè€æ°ã®åãéžæããããã«ã䜿çšã§ããŸãããã®å Žåãã«ã©ã åãã³ã³ãã§åºåã£ãŠåæããŸããäŸãã°ã”users”ããŒãã«ãã”username”ãš”email”ã®åãéžæããã«ã¯ã次ã®ããã«èšè¿°ããŸã:
SELECT username, email FROM users;
ãããã®åºæ¬çãªåœ¢åŒãç解ããããšã§ãSELECTæã䜿ã£ãŠããŒã¿ããŒã¹ããå¿ èŠãªæ å ±ãé©åã«ååŸããããšãã§ããŸãã
5.2 INSERTæãUPDATEæãDELETEæã®äœ¿çš
ããŒã¿ããŒã¹ã«å¯Ÿããæäœã¯ãæ å ±ã®ååŸã ãã§ãªããããŒã¿ã®è¿œå ãå€æŽãåé€ãå«ã¿ãŸããINSERTæãUPDATEæãDELETEæã¯ãããã®æäœãè¡ãããã®SQLã³ãã³ãã§ããããããã®äœ¿çšæ¹æ³ã«ã€ããŠè§£èª¬ããŸãã
INSERTæã¯æ°ããªããŒã¿è¡ãããŒãã«ã«è¿œå ããããã«äœ¿çšããŸããåºæ¬çãªåœ¢åŒã¯ä»¥äžã®éãã§ã:
INSERT INTO table_name (column1, column2, column3,...) VALUES (value1, value2, value3,...);
äŸãã°ã”users”ããŒãã«ã«æ°ãããŠãŒã¶ãŒãè¿œå ããã«ã¯ä»¥äžã®ããã«èšè¿°ããŸã:
INSERT INTO users (username, email) VALUES ('testuser', 'testuser@example.com');
UPDATEæã¯ããŒãã«å ã®æ¢åã®ããŒã¿ãå€æŽããããã«äœ¿çšããŸããåºæ¬çãªåœ¢åŒã¯ä»¥äžã®éãã§ã:
UPDATE table_name SET column1 = value1, column2 = value2,... WHERE condition;
äŸãã°ã”users”ããŒãã«ã®ç¹å®ã®ãŠãŒã¶ãŒã®ã¡ãŒã«ã¢ãã¬ã¹ãå€æŽããã«ã¯ã次ã®ããã«èšè¿°ããŸã:
UPDATE users SET email = 'newemail@example.com' WHERE username = 'testuser';
DELETEæã¯ããŒãã«ããããŒã¿è¡ãåé€ããããã«äœ¿çšããŸããåºæ¬çãªåœ¢åŒã¯ä»¥äžã®éãã§ã:
DELETE FROM table_name WHERE condition;
äŸãã°ã”users”ããŒãã«ããç¹å®ã®ãŠãŒã¶ãŒãåé€ããã«ã¯ã次ã®ããã«èšè¿°ããŸã:
DELETE FROM users WHERE username = 'testuser';
以äžã®åºæ¬çãªåœ¢åŒãç解ããããšã§ãINSERTæãUPDATEæãDELETEæã䜿çšããŠããŒã¿ããŒã¹å ã®ããŒã¿ãå¹æçã«æäœããããšãã§ããŸãã
5.3 WHEREå¥ãšORDER BYå¥ã®äœ¿çš
ããŒã¿ããŒã¹ããããŒã¿ãååŸããéãç¹å®ã®æ¡ä»¶ã«äžèŽããããŒã¿ã ããååŸããããååŸããããŒã¿ãç¹å®ã®é åºã§è¡šç€ºããããšãããããŸãããã®ãããªèŠæ±ãæºããããã«ãSQLã§ã¯WHEREå¥ãšORDER BYå¥ã䜿çšããŸãã
WHEREå¥ã¯ãç¹å®ã®æ¡ä»¶ã«äžèŽããããŒã¿ã®ã¿ãååŸããããã«äœ¿çšããŸããåºæ¬çãªåœ¢åŒã¯ä»¥äžã®éãã§ã:
SELECT column1, column2, ... FROM table_name WHERE condition;
äŸãã°ã”users”ããŒãã«ããç¹å®ã®ãŠãŒã¶ãŒåã®ãŠãŒã¶ãŒã®ã¿ãååŸããã«ã¯ã次ã®ããã«èšè¿°ããŸã:
SELECT * FROM users WHERE username = 'testuser';
ORDER BYå¥ã¯ãååŸããããŒã¿ã®äžŠã³é ãæå®ããããã«äœ¿çšããŸããåºæ¬çãªåœ¢åŒã¯ä»¥äžã®éãã§ã:
SELECT column1, column2, ... FROM table_name ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ... ;
ASCã¯æé ïŒå°ããå€ãã倧ããå€ïŒããDESCã¯éé ïŒå€§ããå€ããå°ããå€ïŒãæå³ããŸããäŸãã°ã”users”ããŒãã«ããå šãŠã®ãŠãŒã¶ãŒããŠãŒã¶ãŒåã®ã¢ã«ãã¡ãããé ã§ååŸããã«ã¯ã次ã®ããã«èšè¿°ããŸã:
SELECT * FROM users ORDER BY username ASC;
ãã®ããã«ãWHEREå¥ãšORDER BYå¥ãããŸã䜿çšããããšã§ãç¹å®ã®æ¡ä»¶ã«äžèŽããããŒã¿ã®ååŸãããŒã¿ã®ãœãŒããšãã£ãåŠçãè¡ãããšãã§ããŸãã
5.4 JOINã®äœ¿çš
ããŒã¿ããŒã¹ã«ãããJOINæäœã¯ãç°ãªãããŒãã«ã®é¢é£ããããŒã¿ãçµã¿åãããããã®åŒ·åãªããŒã«ã§ããJOINãç解ããå¹æçã«äœ¿çšããããšã¯ãããŒã¿ããŒã¹ã䜿ãããªãããã®éèŠãªã¹ãã«ã§ãã
JOINã¯ãåºæ¬çã«ã¯äºã€ã®ããŒãã«ãåãããæäœã§ãããããã®ããŒãã«ã¯äžè¬çã«ãå ±éã®å€ïŒäžè¬çã«ã¯å€éšããŒãšåŒã°ããïŒãæã€åãæã¡ãŸããMySQLã§ã¯ã以äžã®4çš®é¡ã®JOINããããŸãã
INNER JOINïŒINNER JOINã¯ãäºã€ã®ããŒãã«ãå ±æããã¬ã³ãŒãã®ã¿ãçµæãšããŠè¿ããŸããã€ãŸããããŒãã«AãšããŒãã«Bã®äž¡æ¹ã«ååšããè¡ã ããè¿ãããŸãã
LEFT JOINïŒãŸãã¯LEFT OUTER JOINïŒïŒLEFT JOINã¯ã”å·Š”ããŒãã«ïŒJOINã¹ããŒãã¡ã³ãã®æåã«èšè¿°ãããããŒãã«ïŒã®å šãŠã®ã¬ã³ãŒããšã”å³”ããŒãã«ïŒJOINã¹ããŒãã¡ã³ãã®äºçªç®ã«èšè¿°ãããããŒãã«ïŒã®ãããããã¬ã³ãŒããè¿ããŸããå³ããŒãã«ã«ãããããã¬ã³ãŒãããªãå Žåã¯ãNULLå€ãè¿ãããŸãã
RIGHT JOINïŒãŸãã¯RIGHT OUTER JOINïŒïŒRIGHT JOINã¯ãLEFT JOINã®éã®åäœãããŸãã”å³”ããŒãã«ã®å šãŠã®ã¬ã³ãŒããšã”å·Š”ããŒãã«ã®ãããããã¬ã³ãŒããè¿ããŸããå·ŠããŒãã«ã«ãããããã¬ã³ãŒãããªãå Žåã¯ãNULLå€ãè¿ãããŸãã
FULL JOINïŒãŸãã¯FULL OUTER JOINïŒïŒFULL JOINã¯ãMySQLã§ã¯ãµããŒããããŠããŸããããä»ã®å€ãã®ããŒã¿ããŒã¹ã·ã¹ãã ïŒäŸãã°ãPostgreSQLïŒã§ã¯äœ¿çšå¯èœã§ããFULL JOINã¯ãäºã€ã®ããŒãã«ã®äž¡æ¹ããå šãŠã®ã¬ã³ãŒããè¿ããŸããããäžæ¹ã®ããŒãã«ã«ãããããã¬ã³ãŒãããªãå Žåããã®éšåã¯NULLå€ãšãªããŸãã
ãããã®JOINæäœãç解ããé©åã«äœ¿çšããããšã§ãè€æ°ã®ããŒãã«éã§é¢é£ããããŒã¿ãå¹ççã«æ€çŽ¢ãåæãæäœããããšãå¯èœãšãªããŸããããããã®JOINã¿ã€ããã©ã®ãããªç¶æ³ã§æãå¹æçã§ããããç解ããããšã¯ãMySQLã䜿çšããäžã§ã®éèŠãªã¹ãã«ãšãªããŸãã
6. MySQLãšä»ã®ããŒã¿ããŒã¹ãšã®æ¯èŒ
6.1 PostgreSQLãšã®æ¯èŒ
MySQLãšPostgreSQLã¯ãäž¡æ¹ãšã人æ°ã®ãããªãŒãã³ãœãŒã¹ã®ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ç®¡çã·ã¹ãã (RDBMS)ã§ããããããããæã€ç¹åŸŽãšå©ç¹ã«ãããã©ã¡ããéžæãããã¯çšéã«ãããŸãã
äžã€ç®ã®æ¯èŒç¹ãšããŠãæ¡åŒµæ§ãšã«ã¹ã¿ãã€ãºæ§ããããŸããPostgreSQLã¯ãäžçã§æãå é²çãªãªãŒãã³ãœãŒã¹ããŒã¿ããŒã¹ããšèªç§°ããŠããŸããããã¯ãPostgreSQLãé«åºŠã«ã«ã¹ã¿ãã€ãºå¯èœã§ãããå€ãã®æ©èœããŠãŒã¶ãŒã«ãã£ãŠè¿œå ãããæ¡åŒµãããããšãã§ããããã§ããäžæ¹ãMySQLã¯ã·ã³ãã«ããšå©äŸ¿æ§ãéèŠããŠèšèšãããŠãããPostgreSQLã»ã©ã®æ¡åŒµæ§ã¯ãããŸããããããã§ãååãªæ©èœãšæè»æ§ãæã£ãŠããŸãã
äºã€ç®ã®æ¯èŒç¹ãšããŠãããã©ãŒãã³ã¹ãšé床ããããŸããäžè¬çã«ãMySQLã¯èªã¿åããå€ãã¢ããªã±ãŒã·ã§ã³ã«ãããŠåªããããã©ãŒãã³ã¹ãçºæ®ããŸãããã®ãããWebããŒã¹ã®ã¢ããªã±ãŒã·ã§ã³ãã³ã³ãã³ã管çã·ã¹ãã ã«ãã䜿çšãããŸããäžæ¹ãPostgreSQLã¯è€éãªã¯ãšãªãšæžã蟌ã¿ãå€ãã¢ããªã±ãŒã·ã§ã³ã«å¯ŸããŠåªããããã©ãŒãã³ã¹ãæäŸããŸãã
äžã€ç®ã®æ¯èŒç¹ãšããŠããã©ã³ã¶ã¯ã·ã§ã³ãšACIDæºæ ããããŸããACIDãšã¯ãããŒã¿ããŒã¹ãã©ã³ã¶ã¯ã·ã§ã³ã確å®ã«å®äºããããã®ããããã£(Atomicity, Consistency, Isolation, Durability)ã®ç¥ã§ããPostgreSQLã¯å®å šã«ACIDæºæ ã®RDBMSã§ããäžæ¹ãMySQLã¯InnoDBãNDB(Cluster)ãªã©ã®ã¹ãã¬ãŒãžãšã³ãžã³ã䜿çšããããšã§ACIDæºæ ãšãªããŸãããMyISAMãªã©ã®ä»ã®ã¹ãã¬ãŒãžãšã³ãžã³ã¯ACIDæºæ ã§ã¯ãããŸããã
æåŸã«ãã¬ããªã±ãŒã·ã§ã³ã«ã€ããŠã§ããMySQLã¯ãã¹ã¿ãŒ-ã¹ã¬ãŒãã¬ããªã±ãŒã·ã§ã³ãåççã«ãµããŒãããŠãããããã¯ã¹ã±ãŒã©ããªãã£ãšåé·æ§ãæäŸããŸããäžæ¹ãPostgreSQLã¯ãã¹ã¿ãŒ-ãã¹ã¿ãŒã¬ããªã±ãŒã·ã§ãŒã·ã§ã³ããµããŒãããŠãããããã¯é«å¯çšæ§ãšæ éèæ§ãæäŸããŸããããããPostgreSQLã®ãã¹ã¿ãŒ-ãã¹ã¿ãŒã¬ããªã±ãŒã·ã§ã³ã¯ãµãŒãããŒãã£ã®ãœãªã¥ãŒã·ã§ã³ã䜿çšããå¿ èŠããããèšå®ãè€éã«ãªãå¯èœæ§ããããŸãã
ãããã®ããŒã¿ããŒã¹ãåªããæ§èœãæã¡ãç¹å®ã®ããŒãºã«åãããŠèšèšãããŠããŸããPostgreSQLã¯é«åºŠãªã«ã¹ã¿ãã€ãºæ§ãšæ¡åŒµæ§ãæ±ãããŠãŒã¶ãŒã«é©ããŠããŸãããèšå®ãšç®¡çãè€éã«ãªãå¯èœæ§ããããŸããäžæ¹ãMySQLã¯äœ¿ãããããšé床ãéèŠããŠãããWebããŒã¹ã®ã¢ããªã±ãŒã·ã§ã³ãåå¿è ã«ãšã£ãŠé©ããŠããŸãã
ã©ã¡ãã®ããŒã¿ããŒã¹ãéžæãããã¯ãããªãã®ãããžã§ã¯ããããŒã ã®èŠä»¶ããªãœãŒã¹ãã¹ãã«ã»ããã«å€§ããäŸåããŸããæçµçãªéžæãããåã«ãããããã®ããŒã¿ããŒã¹ã®ç¹æ§ãšå©ç¹ãç解ããããšãéèŠã§ãã
6.2 Oracleãšã®æ¯èŒ
次ã«ããªãŒãã³ãœãŒã¹ã®MySQLãšåçšããŒã¿ããŒã¹ã®äžã€ã§ããOracleãšãæ¯èŒããŠã¿ãŸãããããŸããæ倧ã®éãã¯ã©ã€ã»ã³ã¹åœ¢æ ãšã³ã¹ãã§ããOracleã¯åçšããŒã¿ããŒã¹ã§ããããã®äœ¿çšã«ã¯ã©ã€ã»ã³ã¹æãçºçããŸããäžæ¹ãMySQLã¯ç¡æã®ãªãŒãã³ãœãŒã¹ããŒã¿ããŒã¹ã§ãããã³ã¹ããããããªããšãã倧ããªå©ç¹ããããŸãã
ããããã®ããŒã¿ããŒã¹ã®æ©èœã«ã€ããŠãããã€ãã®éãããããŸããOracleã¯äŒæ¥ã¬ãã«ã®æ©èœãåããŠãããé«åºŠãªåææ©èœãé«åºŠãªã»ãã¥ãªãã£æ©èœã匷åãªããã©ãŒãã³ã¹æé©åããŒã«ãªã©ãæäŸããŠããŸãããããããããã®é«åºŠãªæ©èœã¯åŠç¿æ²ç·ãæ¥ã§ãèšå®ã管çãè€éã«ãªãå¯èœæ§ããããŸãã
äžæ¹ãMySQLã¯ããã·ã³ãã«ã§çŽæçãªã€ã³ã¿ãŒãã§ãŒã¹ãæã¡ã䜿ãããããéèŠããŠããŸããããã¯ãæ°ãã«ããŒã¿ããŒã¹ã«è§Šããæ¹ããã·ã³ãã«ãªãŠã§ãã¢ããªã±ãŒã·ã§ã³ãéçºããŠããæ¹ã«ãšã£ãŠå€§ããªå©ç¹ã§ãããŸããMySQLã¯WebããŒã¹ã®ã¢ããªã±ãŒã·ã§ã³ãããã°ãCMSãªã©ã«ãã䜿çšããããã®é åã§ã®æ¯æãéåžžã«é«ãã§ãã
ãããããããã®éããç解ããããã«ã¯ãããããã®ããŒã¿ããŒã¹ã®ç¹æ§ãšå©ç¹ãç解ãããããžã§ã¯ãã®èŠä»¶ãšäžèŽãããã©ãããèããããšãéèŠã§ããããç¹å®ã®ãããžã§ã¯ãã«ã¯MySQLãæé©ã§ãå¥ã®ãããžã§ã¯ãã«ã¯Oracleãæé©ã§ããå¯èœæ§ããããŸãã
6.3 SQL Serverãšã®æ¯èŒ
æåŸã«ãMicrosoftãæäŸããSQL ServerãšMySQLãæ¯èŒããŠã¿ãŸããããSQL Serverã¯ãç¹ã«Windowsç°å¢ã§ã®éçšã«åŒ·ã¿ãæã€åçšã®ãªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ç®¡çã·ã¹ãã ã§ãã
SQL ServerãšMySQLã®äžã€ã®å€§ããªéãã¯ããããããæãå¹æçã«åäœãããã©ãããã©ãŒã ã§ããSQL Serverã¯Microsoft補åãšããŠéçºãããWindowsç°å¢ã§æãå¹æçã«åäœããŸããäžæ¹ãMySQLã¯WindowsãLinuxãMacãªã©ãããŸããŸãªãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§åäœããŸãã
ãŸããäž¡è ã®ã³ã¹ãæ§é ãç°ãªããŸããSQL Serverã¯ã©ã€ã»ã³ã¹æéãçºçããŸããããã®ä»£ããã«å æ¬çãªæè¡ãµããŒããæäŸãããŸããäžæ¹ãMySQLã¯ç¡æã®ãªãŒãã³ãœãŒã¹ããŒã¿ããŒã¹ã§ããããšã³ã¿ãŒãã©ã€ãºçã§ã¯ãµããŒããææãšãªããŸãã
æ©èœæ§ã«ãããŠããSQL Serverã¯ããžãã¹ã€ã³ããªãžã§ã³ã¹ããŒã«ãšã®çµ±åãé«åºŠãªã¬ããŒãã£ã³ã°ããŒã«ãããŒã¿ãŠã§ã¢ããŠã¹ãœãªã¥ãŒã·ã§ã³ãªã©ãäŒæ¥åãã®é«åºŠãªæ©èœãæäŸããŸããäžæ¹ãMySQLã¯ãå¿ èŠãªåºæ¬çãªæ©èœãç¶²çŸ ãã€ã€ããŠãŒã¶ãŒãã¬ã³ããªãŒã§ã·ã³ãã«ãªèšèšãç¹åŸŽã§ãã
ãããã®éããææ¡ããäžã§ãããããã®ããŒã¿ããŒã¹ãæäŸããæ©èœãšç¹æ§ããããŠãããžã§ã¯ãã®èŠä»¶ãšäžèŽãããã©ãããèæ ®ã«å ¥ããããšãéèŠã§ããããããã®ããŒã¿ããŒã¹ãæäŸããç¬èªã®å©ç¹ãšå¶éã«ãã£ãŠãé©åãªããŒã¿ããŒã¹ãéžæããããšãå¯èœã«ãªããŸãã
7. MySQLã®å®çšçãªå©çšäŸ
7.1 Webã¢ããªã±ãŒã·ã§ã³ã§ã®äœ¿çš
å€ãã®ãŠã§ãã¢ããªã±ãŒã·ã§ã³ã§ã¯ãããŒã¿ããŒã¹ãå¿ é ãšãªããŸãããŠãŒã¶ãŒã®ã¢ã«ãŠã³ãæ å ±ãè³Œå ¥å±¥æŽããããã¡ã€ã«æ å ±ãªã©ããŠã§ãã¢ããªã±ãŒã·ã§ã³ã¯ããŸããŸãªçš®é¡ã®ããŒã¿ãåãæ±ãããããããã®ããŒã¿ãå¹ççã«ç®¡çããããã®ããŒã¿ããŒã¹ãå¿ èŠãšãªããŸããããã§MySQLãèŒãç¬éã§ãã
MySQLã¯ããã®é«éæ§ãšä¿¡é Œæ§ãã·ã³ãã«ãããããŠã§ãã¢ããªã±ãŒã·ã§ã³ã®ããã¯ãšã³ããšããŠåºã䜿çšãããŠããŸããç¹ã«ãåçãªãŠã§ãããŒãžãçæããããã®ãµãŒããŒãµã€ãã®ã¹ã¯ãªããèšèªã§ããPHPãšã®çžæ§ãè¯ãããšã§ç¥ãããŠããŸããPHPãšMySQLãçµã¿åãããããšã§ããŠã§ãã¢ããªã±ãŒã·ã§ã³ã¯ãªã¢ã«ã¿ã€ã ã§ããŒã¿ããŒã¹ããæ å ±ãååŸãããŠãŒã¶ãŒã«ãã€ãããã¯ãªã³ã³ãã³ããæäŸããããšãã§ããŸãã
ãŸããMySQLã¯ãã¬ãã·ãã«ãªããŒã¿ããŒã¹ã¹ããŒããæã€ããããŠã§ãã¢ããªã±ãŒã·ã§ã³ã®ããŒã¿èŠä»¶ãå€åããå Žåã§ããæ¯èŒç容æã«ããŒã¿ããŒã¹æ§é ãå€æŽããããšãå¯èœã§ããããã¯ããŠã§ãã¢ããªã±ãŒã·ã§ã³ã®éçºãšéçšã«ãããŠéåžžã«éèŠãªèŠçŽ ãšãªããŸãã
ããã«ãMySQLã¯ã¹ã±ãŒã©ããªãã£ã«åªããŠãããå°èŠæš¡ãªãŠã§ãã¢ããªã±ãŒã·ã§ã³ãã倧èŠæš¡ãªãšã³ã¿ãŒãã©ã€ãºã¢ããªã±ãŒã·ã§ã³ãŸã§å¯Ÿå¿ã§ããŸããããã¯ããŠã§ãã¢ããªã±ãŒã·ã§ã³ãæé·ãããŠãŒã¶ãŒããŒã¹ãå¢å ããå Žåã§ããããŒã¿ããŒã¹ã®ããã©ãŒãã³ã¹ãç¶æãããããšãæå³ããŸãã
以äžã®ãããªçç±ããããŠã§ãã¢ããªã±ãŒã·ã§ã³éçºã«ãããŠMySQLã¯éåžžã«éèŠãªåœ¹å²ãæãããŠããŸãããããã®ç¹æ§ã¯ãMySQLããŠã§ãã¢ããªã±ãŒã·ã§ã³ã®ããŒã¿ããŒã¹ãšããŠåºãéžã°ããçç±ãæ確ã«ç€ºããŠããŸãã
7.2 ããã°ããŒã¿ãšåæ
çŸä»£ã®ããžãã¹ã«ãããŠãããã°ããŒã¿ãšãã®åæã¯çµç¹ã®ç«¶äºåãé«ããéèŠãªèŠçŽ ãšãªã£ãŠããŸããèšå€§ãªéã®ããŒã¿ãå¹æçã«ç®¡çãããã®äžããæçšãªæŽå¯ãåŒãåºãããã«ã¯ãå ç¢ã§ã¹ã±ãŒã©ãã«ãªããŒã¿ããŒã¹ã·ã¹ãã ãå¿ èŠãšãªããŸããããã§ãMySQLããã®åãçºæ®ããŸãã
MySQLã¯ããã®æ¡åŒµæ§ãšããã©ãŒãã³ã¹ã®é«ããããããã°ããŒã¿ã®ç®¡çãšåæã«åºã䜿çšãããŠããŸããMySQLã¯ãã©ãã€ãçŽã®ããŒã¿ãåãæ±ãããšãå¯èœã§ãããã€ã³ããã¯ã¹ã䜿çšããé«éãªããŒã¿æ€çŽ¢ãå¯èœãªããã倧èŠæš¡ãªããŒã¿ã»ããã«å¯Ÿããã¯ãšãªãè¿ éã«åŠçã§ããŸãã
ããã«ãMySQLã¯é«åºŠãªåææ©èœãåããŠããŸããããšãã°ãMySQLã¯çªé¢æ°ãå ±éããŒãã«åŒïŒCTEïŒãªã©ã®SQLæšæºã®é«åºŠãªæ©èœããµããŒãããŠããŸãããããã®æ©èœã䜿çšããããšã§ããŠãŒã¶ãŒã¯è€éãªããŒã¿åæã¯ãšãªãäœæããæ·±ãæŽå¯ãåŸãããšãã§ããŸãã
ãŸããMySQLã¯å€ãã®ããã°ããŒã¿ããŒã«ãšçµ±åããããšãå¯èœã§ããããšãã°ãApache HadoopãApache Sparkãªã©ã®ããã°ããŒã¿åŠçãã¬ãŒã ã¯ãŒã¯ãšMySQLãé£æºãããããšã§ãããã°ããŒã¿ã®åæãšåŠçãããå¹ççã«è¡ãããšãã§ããŸãã
ãããã®çç±ãããããã°ããŒã¿ãšãã®åæã«ãããŠãMySQLã¯éèŠãªåœ¹å²ãæãããŠããŸãããããã®ç¹æ§ã¯ãMySQLãããã°ããŒã¿ã®ããŒã¿ããŒã¹ãšããŠåºãéžã°ããçç±ãæ確ã«ç€ºããŠããŸãã
7.3 ã·ã¹ãã 管ç
ã·ã¹ãã 管çãšãããšé£ãããã«æãããããããŸããããMySQLã§ã¯ãã®äœæ¥ãéåžžã«å®¹æã§ããããšãã°ãMySQLã§ã¯ãŠãŒã¶ãŒãèšå®ã調æŽããã·ã¹ãã ã®ããã©ãŒãã³ã¹ãæé©åããããã®å€ãã®ããŒã«ãæäŸãããŠããŸããããã«ã¯ãMySQL Workbenchãšããã°ã©ãã£ã«ã«ãªã€ã³ã¿ãŒãã§ãŒã¹ãæã€ç®¡çããŒã«ãå«ãŸããŸãã
MySQL Workbenchã§ã¯ãããŒã¿ããŒã¹ã®èšèšãéçºã管çãäžå çã«è¡ãããšãã§ããŸãããŸããWorkbenchã®ããã©ãŒãã³ã¹ããã·ã¥ããŒãã䜿çšãããšãããŒã¿ããŒã¹ã®ããã©ãŒãã³ã¹ããªã¢ã«ã¿ã€ã ã§ç£èŠããåé¡ãçºçããå Žåã«è¿ éã«å¯ŸåŠããããšãå¯èœã§ãã
ãŸããMySQLã¯æ¡åŒµæ§ãé«ããåçš®ãã©ã°ã€ã³ãå©çšããããšã§ã·ã¹ãã 管çãããå¹ççã«è¡ãããšãã§ããŸããäŸãã°ãã»ãã¥ãªãã£ãã©ã°ã€ã³ã䜿çšããã°ãããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹ãå³æ Œã«å¶åŸ¡ããæ å ±æŒæŽ©ã®ãªã¹ã¯ãæå°éã«æããããšãå¯èœã§ãã
ããã«ãMySQLã¯ã¯ã©ãŠãããŒã¹ã®ããŒã¿ããŒã¹ãµãŒãã¹ãšããŠãæäŸãããŠããŸããããã«ãããã·ã¹ãã ã®èšå®ãã¡ã³ããã³ã¹ãæéãªãè¡ãããšãå¯èœã«ãªããŸããç¹ã«ãAmazon RDSãGoogle Cloud SQLãªã©ã®ã¯ã©ãŠããµãŒãã¹ã§ã¯ãMySQLã®ã€ã³ã¹ã¿ã³ã¹ã®ç®¡çãã¹ã±ãŒãªã³ã°ãèªååã§ããŸãã
ãããã®æ©èœã«ãããMySQLã¯ã·ã¹ãã 管çã®èŠ³ç¹ããèŠãŠãéåžžã«åªããéžæè¢ãšãªããŸãããããã®ããŒã«ãšãµãŒãã¹ã掻çšããããšã§ãããŒã¿ããŒã¹ã®ç®¡çãã¯ããã«å®¹æã«ãªããæéãšãªãœãŒã¹ãç¯çŽããããšãå¯èœã«ãªããŸãã
8. ãŸãšããšä»åŸã®åŠã³æ¹
8.1 ãŸãšã
ãã®èšäºã§ã¯ãMySQLã®æŠèŠãšãã®äž»ãªç¹åŸŽãå©çšæ¹æ³ãä»ã®ããŒã¿ããŒã¹ã·ã¹ãã ãšã®æ¯èŒããããŠå ·äœçãªäœ¿çšäŸã«ã€ããŠè©³ããèŠãŠããŸããã
MySQLã¯ãå ç¢æ§ãããã©ãŒãã³ã¹ãæè»æ§ããããŠç°¡ææ§ãå Œãåãããªã¬ãŒã·ã§ãã«ããŒã¿ããŒã¹ã·ã¹ãã ã§ããããã®åŒ·åãªæ©èœãšæ¡åŒµæ§ã«ãããæ§ã ãªçšéã§åºã掻çšãããŠããŸãããŸãããªãŒãã³ãœãŒã¹ã§ããããšããããŠãŒã¶ãŒã¯èªåã®ããŒãºã«åãããŠMySQLãèªç±ã«ã«ã¹ã¿ãã€ãºããããšãã§ããŸãã
ãŸããã¯ãšãªã®æé©åãJOINã®äœ¿çšãªã©ãMySQLã®åºæ¬çãªæäœæ¹æ³ã«ã€ããŠã説æããŸããããããã®æ©èœãç解ããé©åã«æŽ»çšããããšã§ãããŒã¿ã®ç®¡çãåæãå¹ççã«è¡ãããšãå¯èœã§ãã
ä»ã®ããŒã¿ããŒã¹ã·ã¹ãã ãšã®æ¯èŒã§ã¯ãMySQLãPostgreSQLãOracleãSQL Serverãšãã£ãä»ã®äž»èŠãªããŒã¿ããŒã¹ã·ã¹ãã ãšã©ã®ããã«éããããããã®ã·ã¹ãã ãæé©ãšãªãç¶æ³ã«ã€ããŠè©³ããèŠãŠããŸããããããã®æ¯èŒãéããŠãèªåã®ãããžã§ã¯ããããžãã¹ããŒãºã«æé©ãªããŒã¿ããŒã¹ã·ã¹ãã ãéžæããããã®èŠç¹ãåŸãããšãã§ããŸãã
æåŸã«ãMySQLãWebã¢ããªã±ãŒã·ã§ã³ãããã°ããŒã¿åæããããŠã·ã¹ãã 管çãšãã£ãå ·äœçãªã·ããªãªã§ã©ã®ããã«æŽ»çšã§ãããã«ã€ããŠèª¬æããŸããããããã®äœ¿çšäŸãããMySQLãã©ãã»ã©å€æ©èœã§å€ç®çãªããŒã¿ããŒã¹ã·ã¹ãã ã§ããããç解ããããšãã§ããŸãã
å šãŠããŸãšãããšãMySQLã¯ãã®è±å¯ãªæ©èœãšé«ãæ¡åŒµæ§ãæè»æ§ã掻ãããŠãããŸããŸãªèŠä»¶ã«å¯Ÿå¿ããä¿¡é Œæ§ã®é«ãããŒã¿ããŒã¹ã·ã¹ãã ãšèšããŸããããããããã®å©çšç¯å²ã¯åºããç¶ããæ å ±ç€ŸäŒã®ããŸããŸãªå Žé¢ã§æŽ»èºããããšã§ãããã
8.2 ä»åŸã®åŠã³æ¹ãšè³æº
ãã®èšäºãéããŠãMySQLã®åºæ¬çãªæŠå¿µãšäœ¿çšæ¹æ³ã«ã€ããŠåŠãã ããšã§ããããããããMySQLã®çã®åãåŒãåºãããã«ã¯ãç¶ç¶çãªåŠç¿ãšå®è·µãå¿ èŠã§ããããã§ã¯ãMySQLã«ã€ããŠããã«æ·±ãåŠã¶ããã®åŠç¿æ¹æ³ãšè³æºãæäŸããŸãã
æåã«æšå¥šããã®ã¯ãå ¬åŒã®MySQLããã¥ã¡ã³ããŒã·ã§ã³ã§ããããã¯MySQLã®å šãŠã®æ©èœãšæäœã«ã€ããŠè©³çŽ°ã«èª¬æããŠãããæãä¿¡é Œæ§ã®é«ãæ å ±æºãšèšããŸãããŸããå ·äœçãªåé¡è§£æ±ºã®ããã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°ã¬ã€ãããã¹ããã©ã¯ãã£ã¹ãæäŸããŠããŸãã
次ã«ããªã³ã©ã€ã³ã³ãŒã¹ãå¹æçãªåŠç¿æ¹æ³ã§ããUdemyãCourseraãªã©ã®ãã©ãããã©ãŒã ã§ã¯ãåºæ¬çãªæäœããé«åºŠãªãã¯ããã¯ãŸã§ãã«ããŒããMySQLã®ã³ãŒã¹ãå€æ°æäŸããŠããŸãããããã®ã³ãŒã¹ã¯ãèªåã®ããŒã¹ã§åŠã¶ããšãã§ããè±å¯ãªå®è·µäŸã§ç解ãæ·±ããããšãã§ããŸãã
ãŸããã³ãã¥ããã£ãã©ãŒã©ã ãStack Overflowãšãã£ã質åå¿çãµã€ãããåé¡è§£æ±ºã®æå©ããšãªããŸããããã§ã¯ãåãåé¡ãæ±ããŠããä»ã®éçºè ããã®å©ããåŸãããšãã§ãããŸãèªåãç¥èãå ±æããæ©äŒããããŸãã
æåŸã«ãèªåèªèº«ã§ãããžã§ã¯ããäœæããããšããåŠç¿ã匷åããæå¹ãªæ¹æ³ã§ããå®éã«æãåãããŠããŒã¿ããŒã¹ãäœæããã¯ãšãªãæžãããšã§ãçè«çãªç¥èãå®è·µçãªã¹ãã«ã«å€æããããšãã§ããŸãã
ãããã®è³æºãšåŠç¿æ¹æ³ãå©çšããŠãMySQLã®ã¹ãã«ãäžå±€ç£šããŸãããããããŠãããŒã¿é§ååã®äžçã§ãèªåèªèº«ã®äŸ¡å€ãé«ããããã®ã¹ããããèžãã§ãã ããã