1. ã¯ããã«
mysqldumpã³ãã³ããšã¯ïŒ
ããŒã¿ããŒã¹ã®ããã¯ã¢ããã移è¡ã¯ãã·ã¹ãã 管çãéçºã«ãããŠæ¬ ãããªãäœæ¥ã§ãããã®éã«åœ¹ç«ã€ã®ããmysqldumpãã³ãã³ãã§ãã
mysqldumpã¯ãMySQLããŒã¿ããŒã¹ã®å
容ããšã¯ã¹ããŒãããŠä¿åããããã®ãŠãŒãã£ãªãã£ã§ãããŒã¿ããŒã¹ç®¡çã·ã¹ãã ïŒDBMSïŒãå©çšããå€ãã®çŸå Žã§æŽ»çšãããŠããŸãã
mysqldumpã®ç¹åŸŽ
- ããã¯ã¢ããæ©èœ – ããŒã¿ããŒã¹ã®å 容ãSQLã¹ã¯ãªãããšããŠåºåããçœå®³ããã©ãã«æã«ããŒã¿ã埩æ§ã§ããããã«ããŸãã
- 移è¡æ©èœ – ç°ãªãç°å¢ããµãŒããŒãžã®ããŒã¿ç§»è¡ãã¹ã ãŒãºã«è¡ãããšãã§ããŸãã
- æè»æ§ – ããŒãã«åäœãæ¡ä»¶ä»ãã§ãšã¯ã¹ããŒããå¯èœãªãããéšåçãªããã¯ã¢ããã«ã察å¿ããŸãã
ãã®ããã«ãmysqldumpã³ãã³ãã¯ããŒã¿ã®å®å šæ§ãšç®¡çã®å¹çåããµããŒããã匷åãªããŒã«ã§ãã
ãã®èšäºã®ç®çãšå¯Ÿè±¡èªè
ãã®ã¬ã€ãã§ã¯ãmysqldumpã³ãã³ãã®åºæ¬çãªäœ¿ãæ¹ããé«åºŠãªãªãã·ã§ã³ã®æŽ»çšæ¹æ³ãŸã§ã詳ãã解説ããŸãã
察象èªè
- åå¿è ïŒ MySQLã®æäœã«ãŸã æ £ããŠããªãããããã¯ã¢ããã埩å ã®åºæ¬ãåŠã³ããæ¹ã
- äžçŽè ïŒ å®è·µçãªmysqldumpã³ãã³ãã®äœ¿ãæ¹ãç¿åŸããæ¥åå¹çãé«ãããæ¹ã
- éçºè ã»éçšæ åœè ïŒ ããŒã¿ããŒã¹ç®¡çã«é¢ããç¥èãæ·±ãããã©ãã«çºçæã«ãè¿ éã«å¯Ÿå¿ãããæ¹ã
ãã®èšäºã§åŠã¹ãããš
- mysqldumpã³ãã³ãã®åºæ¬æ§æãšäœ¿çšäŸ
- ããŒã¿ããŒã¹ãããŒãã«ã®ãšã¯ã¹ããŒããšã€ã³ããŒãæ¹æ³
- ãã©ãã«ã·ã¥ãŒãã£ã³ã°ããšã©ãŒè§£æ±ºç
- ããã¯ã¢ããã®èªååãšã»ãã¥ãªãã£å¯Ÿç
ãããã®å 容ãéããŠãmysqldumpãå¹æçã«æŽ»çšããå®å šã§å¹ççãªããŒã¿ç®¡çãå®çŸã§ããããã«ãªããŸãã
2. mysqldumpã³ãã³ãã®åºæ¬ãšã§ããããš
mysqldumpã®æŠèŠ
mysqldumpã¯ãMySQLããã³MariaDBããŒã¿ããŒã¹ã®ããã¯ã¢ããã移è¡ã«äœ¿çšãããã³ãã³ãã©ã€ã³ããŒã«ã§ãããã®ããŒã«ã¯ãããŒã¿ããŒã¹ã®æ§é ãšããŒã¿ãSQL圢åŒãŸãã¯ããã¹ã圢åŒã§ãšã¯ã¹ããŒãããŸãã
mysqldumpã®äž»ãªæ©èœ
- ããŒã¿ããŒã¹å
šäœã®ããã¯ã¢ããïŒ
ããŒã¿ãšã¹ããŒãã®äž¡æ¹ãå«ãå®å šãªããã¯ã¢ãããååŸããŸãã - éšåããã¯ã¢ããïŒ
ç¹å®ã®ããŒãã«ã®ã¿ããšã¯ã¹ããŒãã§ããããã倧èŠæš¡ãªããŒã¿ããŒã¹ã§ãå¹ççã«ç®¡çã§ããŸãã - ããŒã¿ç§»è¡ïŒ
ããŒã¿ããŒã¹ãå¥ã®ãµãŒããŒãç°å¢ã«ç§»è¡ããéã«ã䟿å©ã§ãã - èšå®ãæš©éã®ãšã¯ã¹ããŒãïŒ
ã¹ãã¢ãããã·ãŒãžã£ãããªã¬ãŒããã¥ãŒãªã©ããšã¯ã¹ããŒãã§ãããããç°å¢ã®åçŸæ§ãé«ãŸããŸãã
䜿çšã·ãŒã³å¥ã®æŽ»çšäŸ
- éçºç°å¢ãžã®ããŒã¿è€è£œïŒ æ¬çªç°å¢ããéçºç°å¢ã«ããŒã¿ã移ããŠãã¹ããè¡ãéã«äœ¿çšã
- ããŒã¿ã®ã¢ãŒã«ã€ãïŒ å€ãããŒã¿ãããã¯ã¢ããããŠããã£ã¹ã¯å®¹éãç¯çŽããçšéã
- çœå®³åŸ©æ§å¯ŸçïŒ ããŒããŠã§ã¢é害ãããŒã¿ç Žææã®ãªã«ããªãŒçšã«å®æçã«ããã¯ã¢ãããä¿åã
ã€ã³ã¹ããŒã«ãšåºæ¬èšå®
mysqldumpã®ã€ã³ã¹ããŒã«ç¢ºèª
mysqldumpã¯ãMySQLãŸãã¯MariaDBã®æšæºããã±ãŒãžã«å«ãŸããŠããŸãã以äžã®ã³ãã³ãã§ã€ã³ã¹ããŒã«ç¶æ ã確èªã§ããŸãïŒ
mysqldump --version
çµæäŸïŒ
mysqldump Ver 8.0.26 for Linux on x86_64 (MySQL Community Server - GPL)
ã€ã³ã¹ããŒã«ãããŠããªãå Žå
ã·ã¹ãã ã«ãã£ãŠã¯mysqldumpãå«ãŸããŠããªãããšããããŸãããã®å Žåã¯ä»¥äžã®ã³ãã³ãã§ã€ã³ã¹ããŒã«ããŸãïŒ
Ubuntu/Debianç³»ã®å ŽåïŒ
sudo apt-get install mysql-client
CentOS/RHELç³»ã®å ŽåïŒ
sudo yum install mysql
æ¥ç¶èšå®ã®ãã€ã³ã
mysqldumpã䜿çšããããã«ã¯ãæ¥ç¶æ å ±ãå¿ èŠã§ããåºæ¬çãªæ¥ç¶èšå®ã¯ä»¥äžã®éãã§ãïŒ
mysqldump -u ãŠãŒã¶ãŒå -p ãã¹ã¯ãŒã ããŒã¿ããŒã¹å > backup.sql
- -uïŒMySQLãŠãŒã¶ãŒåãæå®ããŸãã
- -pïŒãã¹ã¯ãŒãå ¥åãæ±ãããªãã·ã§ã³ã§ãã
- ããŒã¿ããŒã¹åïŒããã¯ã¢ãããããããŒã¿ããŒã¹åãæå®ããŸãã
- > backup.sqlïŒåºåå ãã¡ã€ã«åãæå®ããŸãã
æ¥ç¶ãšã©ãŒæã®å¯ŸåŠæ³
- èªèšŒãšã©ãŒã®å ŽåïŒ
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)
â ãŠãŒã¶ãŒåããã¹ã¯ãŒãã®èª€ãããªãã確èªããé©åãªæš©éãä»äžããŸãã
- ãã¹ãæå®ãšã©ãŒã®å ŽåïŒ
ERROR 2003 (HY000): Can't connect to MySQL server on 'hostname' (111)
â ãã¡ã€ã¢ãŠã©ãŒã«èšå®ãMySQLãµãŒãã¹ã®ç¶æ ã確èªããŸãã
3. mysqldumpã®åºæ¬çãªäœ¿ãæ¹
åäžããŒã¿ããŒã¹ã®ããã¯ã¢ããæé
mysqldumpã³ãã³ãã䜿ãããšã§ãç¹å®ã®ããŒã¿ããŒã¹ãç°¡åã«ããã¯ã¢ããã§ããŸãã以äžã®äŸã§ã¯ãããŒã¿ããŒã¹åãexample_dbãã®ããã¯ã¢ãããååŸããŸãã
åºæ¬ã³ãã³ãäŸ
mysqldump -u ãŠãŒã¶ãŒå -p example_db > backup.sql
ã³ãã³ã解説
- -u ãŠãŒã¶ãŒåïŒããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹æš©éãæã€ãŠãŒã¶ãŒãæå®ããŸãã
- -pïŒãã¹ã¯ãŒãå ¥åãä¿ããŸãïŒå ¥åæã¯é衚瀺ïŒã
- example_dbïŒããã¯ã¢ãããããããŒã¿ããŒã¹åãæå®ããŸãã
- > backup.sqlïŒããã¯ã¢ãããã¡ã€ã«ã®ä¿åå ãšååãæå®ããŸãã
ããã¯ã¢ããçµæã®ç¢ºèª
äœæããããbackup.sqlããã¡ã€ã«ãããã¹ããšãã£ã¿ã§éããšãSQLæã®åœ¢åŒã§ããŒãã«äœæãããŒã¿æ¿å ¥ãèšèŒãããŠããããšã確èªã§ããŸãã
è€æ°ããŒã¿ããŒã¹ã®ããã¯ã¢ããæ¹æ³
è€æ°ã®ããŒã¿ããŒã¹ãäžåºŠã«ããã¯ã¢ããããå Žåã¯ã以äžã®ã³ãã³ãã䜿çšããŸãã
è€æ°ããŒã¿ããŒã¹ã®äŸ
mysqldump -u ãŠãŒã¶ãŒå -p --databases db1 db2 > multi_backup.sql
ãªãã·ã§ã³è§£èª¬
- –databasesïŒè€æ°ã®ããŒã¿ããŒã¹åãæå®ããå Žåã«å¿ èŠã§ãã
- db1 db2ïŒããã¯ã¢ããããããŒã¿ããŒã¹åãåè§ã¹ããŒã¹ã§åºåã£ãŠæå®ããŸãã
ãã®æ¹æ³ã§ã¯ãæå®ããè€æ°ã®ããŒã¿ããŒã¹ã1ã€ã®ãã¡ã€ã«ã«ãšã¯ã¹ããŒããããŸãã
ç¹å®ããŒãã«ã®ã¿ãããã¯ã¢ããããæ¹æ³
倧èŠæš¡ãªããŒã¿ããŒã¹ããç¹å®ã®ããŒãã«ã ããããã¯ã¢ããããå Žåã¯ã以äžã®ã³ãã³ãã䜿çšããŸãã
ç¹å®ããŒãã«ã®äŸ
mysqldump -u ãŠãŒã¶ãŒå -p example_db table1 table2 > tables_backup.sql
ãªãã·ã§ã³è§£èª¬
- example_dbïŒå¯Ÿè±¡ããŒã¿ããŒã¹åãæå®ããŸãã
- table1 table2ïŒããã¯ã¢ããããããŒãã«åãã¹ããŒã¹åºåãã§æå®ããŸãã
ãã®æ¹æ³ã¯ãç¹å®ã®ããŒã¿ã ããå¹ççã«ããã¯ã¢ãããããå Žåã«äŸ¿å©ã§ãã
ããã¯ã¢ãããã¡ã€ã«ãå§çž®ããæ¹æ³
ããã¯ã¢ãããã¡ã€ã«ã倧ãããªãå Žåã¯ãgzipã§å§çž®ããããšãããããããŸãã
å§çž®ããã¯ã¢ããã®äŸ
mysqldump -u ãŠãŒã¶ãŒå -p example_db | gzip > backup.sql.gz
ã³ãã³ã解説
- | gzipïŒmysqldumpã®åºåãgzipã§å§çž®ããŸãã
- backup.sql.gzïŒå§çž®ãããããã¯ã¢ãããã¡ã€ã«åã§ãã
ãã®æ¹æ³ã«ãããã¹ãã¬ãŒãžã®ç¯çŽãšããã¯ã¢ããã®è»¢éé床åäžãæåŸ ã§ããŸãã
ããŒã¿ããŒã¹ã®ãªã¹ãã¢æé
mysqldumpã§ååŸããããã¯ã¢ããã¯ã以äžã®ã³ãã³ãã§ç°¡åã«ãªã¹ãã¢ã§ããŸãã
ãªã¹ãã¢ã®åºæ¬äŸ
mysql -u ãŠãŒã¶ãŒå -p example_db < backup.sql
ã³ãã³ã解説
- mysqlïŒMySQLã¯ã©ã€ã¢ã³ããåŒã³åºããŸãã
- example_dbïŒãªã¹ãã¢å ã®ããŒã¿ããŒã¹åãæå®ããŸãã
- < backup.sqlïŒããã¯ã¢ãããã¡ã€ã«ããããŒã¿ãã€ã³ããŒãããŸãã
泚æç¹ãšæšå¥šäºé
- äºåã«ããŒã¿ããŒã¹ãäœæããïŒ
ãªã¹ãã¢å ã®ããŒã¿ããŒã¹ãååšããªãå Žåã¯ããããããäœæããŠããå¿ èŠããããŸãã
CREATE DATABASE example_db;
- 倧èŠæš¡ããŒã¿ã®åå²ã€ã³ããŒãïŒ
ããŒã¿éã倧ããå Žåã¯ããã¡ã€ã«åå²ãå§çž®ããŒã¿ã®å±éãçµã¿åãããŠå¹çåããŸãã - æåã³ãŒãã®ç¢ºèªïŒ
ããã¯ã¢ãããšãªã¹ãã¢æã«æååããé²ããããæåã³ãŒãèšå®ã確èªããŠãã ããã
mysqldump --default-character-set=utf8 -u ãŠãŒã¶ãŒå -p example_db > backup.sql
ã
4. mysqldumpã®äŸ¿å©ãªãªãã·ã§ã³è§£èª¬
mysqldumpã³ãã³ãã«ã¯å€ãã®ãªãã·ã§ã³ãçšæãããŠãããç¹å®ã®ããŒãºã«å¿ããŠããŒã¿ã®ãšã¯ã¹ããŒãã管çãå¹çåã§ããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãç¹ã«å®çšæ§ã®é«ããªãã·ã§ã³ã«ã€ããŠè©³ãã解説ããŸãã
ããŒã¿æŽåæ§ã確ä¿ãããªãã·ã§ã³
–single-transaction
mysqldump --single-transaction -u ãŠãŒã¶ãŒå -p example_db > backup.sql
解説
- ãã©ã³ã¶ã¯ã·ã§ã³ã®äžè²«æ§ã確ä¿ããªããããã¯ã¢ãããååŸããŸãã
- ç¹ã«InnoDBã¹ãã¬ãŒãžãšã³ãžã³ã䜿çšããŠããå Žåã«æå¹ã§ãã
- 倧èŠæš¡ãªããŒã¿ããŒã¹ã®ããã¯ã¢ããæã«ããã¯ãæå°éã«æããããšãã§ããŸãã
䜿çšäŸ
ãªã³ã©ã€ã³ãµãŒãã¹ãåæ¢ããã«ããã¯ã¢ãããååŸããéã«åœ¹ç«ã¡ãŸãã
ã¡ã¢ãªäœ¿çšéãæãããªãã·ã§ã³
–quick
mysqldump --quick -u ãŠãŒã¶ãŒå -p example_db > backup.sql
解説
- ããŒã¿ãäžè¡ãã€ååŸããã¡ã¢ãªäœ¿çšéãæãããªãã·ã§ã³ã§ãã
- ç¹ã«å€§èŠæš¡ããŒã¿ããŒã¹ã®ããã¯ã¢ããã«é©ããŠããŸãã
泚æç¹
- ããã©ãŒãã³ã¹ãåäžãããäžæ¹ã§ãå®è¡æéã¯å€å°é·ããªãå¯èœæ§ããããŸãã
ã¹ãã¢ãããã·ãŒãžã£ãããªã¬ãŒã®ããã¯ã¢ãã
–routines ãš –triggers
mysqldump --routines --triggers -u ãŠãŒã¶ãŒå -p example_db > backup.sql
解説
- –routinesïŒã¹ãã¢ãããã·ãŒãžã£ãšãã¡ã³ã¯ã·ã§ã³ãå«ããŠããã¯ã¢ããããŸãã
- –triggersïŒããªã¬ãŒããšã¯ã¹ããŒãããŸãã
䜿çšäŸ
è€éãªããžãã¹ããžãã¯ãèªååŠçãä¿æãããŸãŸããã¯ã¢ããã»ç§»è¡ãè¡ãããå Žåã«äœ¿çšããŸãã
ããŒã¿ãšã¹ããŒããåããŠä¿åãããªãã·ã§ã³
–no-data
mysqldump --no-data -u ãŠãŒã¶ãŒå -p example_db > schema.sql
解説
- ããŒãã«æ§é ã®ã¿ããšã¯ã¹ããŒãããããŒã¿ã¯å«ããŸããã
- éçºç°å¢ã§ã¹ããŒãã®æ€èšŒãåæ§ç¯ãè¡ãå Žåã«äŸ¿å©ã§ãã
ããŒã¿è¿œå æã®å®å šå¯Ÿçãªãã·ã§ã³
–add-drop-table
mysqldump --add-drop-table -u ãŠãŒã¶ãŒå -p example_db > backup.sql
解説
- ããŒãã«äœæåã«æ¢åã®ããŒãã«ãåé€ããSQLæãå«ããŸãã
- æ¢åããŒã¿ãå®å šã«äžæžãããéã«åœ¹ç«ã¡ãŸãã
泚æç¹
ãªã¹ãã¢æã«æ¢åã®ããŒã¿ãæ¶å»ããå¯èœæ§ããããããå®è¡åã«ååã«æ€èšŒããŠãã ããã
ããŒã¿ãã£ã«ã¿ãªã³ã°çšãªãã·ã§ã³
–where
mysqldump -u ãŠãŒã¶ãŒå -p example_db --where="created_at >= '2023-01-01'" > filtered_backup.sql
解説
- ç¹å®ã®æ¡ä»¶ã«äžèŽããããŒã¿ã®ã¿ããšã¯ã¹ããŒãã§ããŸãã
- 倧èŠæš¡ãªããŒã¿ããŒã¹ã®äžéšããŒã¿ãæœåºããéã«åœ¹ç«ã¡ãŸãã
å§çž®ããŠããã¯ã¢ãããããªãã·ã§ã³
–compress
mysqldump --compress -u ãŠãŒã¶ãŒå -p example_db > backup.sql
解説
- ãµãŒããŒãšã¯ã©ã€ã¢ã³ãéã®ããŒã¿è»¢éãå§çž®ããŸãã
- ãããã¯ãŒã¯è¶ãã®ããã¯ã¢ããååŸæã«è»¢éé床ãåäžãããŸãã
ãã®ä»äŸ¿å©ãªãªãã·ã§ã³ãŸãšã
ãªãã·ã§ã³å | 説æ |
---|---|
–skip-lock-tables | ããŒãã«ããã¯ãåé¿ããŠãšã¯ã¹ããŒããé«éåããŸãã |
–default-character-set | æåã³ãŒããæå®ããŸãïŒäŸïŒutf8 ïŒã |
–result-file | åºåãã¡ã€ã«ã«çŽæ¥æžã蟌ã¿ãããã©ãŒãã³ã¹ãåäžããŸãã |
–hex-blob | ãã€ããªããŒã¿ã16é²æ°åœ¢åŒã§ãšã¯ã¹ããŒãããŸãã |
–no-create-info | ããŒã¿ã®ã¿ãšã¯ã¹ããŒãããããŒãã«å®çŸ©ã¯å«ããŸããã |
ãŸãšã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãmysqldumpã³ãã³ãã®äŸ¿å©ãªãªãã·ã§ã³ã«ã€ããŠè©³ãã解説ããŸããããããã®ãªãã·ã§ã³ãé©åã«æŽ»çšããããšã§ãããã¯ã¢ãããããŒã¿ç§»è¡ã®å¹çãšå®å šæ§ãå€§å¹ ã«åäžãããããšãã§ããŸãã
5. å®è·µäŸïŒWordPressã®ããã¯ã¢ãããšãªã¹ãã¢
WordPressã¯MySQLããŒã¿ããŒã¹ã䜿çšããŠãµã€ãæ å ±ã管çããŠããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ãmysqldumpã³ãã³ãã䜿çšããŠWordPressã®ããŒã¿ããŒã¹ãããã¯ã¢ããããã³ãªã¹ãã¢ããå ·äœçãªæé ã解説ããŸãã
WordPressãµã€ãã®ããã¯ã¢ããæé
1. ããŒã¿ããŒã¹æ å ±ã®ç¢ºèª
ãŸããWordPressã®èšå®ãã¡ã€ã«ïŒwp-config.php
ïŒããããŒã¿ããŒã¹åããŠãŒã¶ãŒåããã¹ã¯ãŒãã確èªããŸãã
èšå®ãã¡ã€ã«ã®äŸïŒ
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'wp_password');
define('DB_HOST', 'localhost');
2. ããŒã¿ããŒã¹ã®ããã¯ã¢ããã³ãã³ã
以äžã®ã³ãã³ããå®è¡ããŠãWordPressããŒã¿ããŒã¹ãããã¯ã¢ããããŸãã
mysqldump -u wp_user -p wordpress_db > wordpress_backup.sql
ãªãã·ã§ã³èª¬æïŒ
- -u wp_userïŒWordPressã§äœ¿çšããŠããããŒã¿ããŒã¹ãŠãŒã¶ãŒã
- -pïŒãã¹ã¯ãŒãå ¥åãæ±ãããªãã·ã§ã³ã
- wordpress_dbïŒããŒã¿ããŒã¹åã
- > wordpress_backup.sqlïŒããã¯ã¢ãããã¡ã€ã«åã
3. å§çž®ããŠããã¯ã¢ããããäŸ
ãã¡ã€ã«ãµã€ãºãæããããã«ãgzipãå©çšããŠå§çž®ããå ŽåïŒ
mysqldump -u wp_user -p wordpress_db | gzip > wordpress_backup.sql.gz
4. ãã¡ã€ã«è»¢éã®æšå¥šæ¹æ³
ããã¯ã¢ãããã¡ã€ã«ã¯å®å šãªå Žæã«ä¿åããå¿ èŠããããŸãã以äžã®äŸã¯ãSCPã³ãã³ãã䜿çšããŠãªã¢ãŒããµãŒããŒã«è»¢éããŸãã
scp wordpress_backup.sql.gz user@remote_host:/backup/
埩å æé ãšæ³šæç¹
1. æ°ããããŒã¿ããŒã¹ã®äœæ
ãªã¹ãã¢å ã«æ°ããããŒã¿ããŒã¹ãäœæããŸãã
mysql -u root -p -e "CREATE DATABASE wordpress_db;"
2. ããŒã¿ããŒã¹ã®ãªã¹ãã¢
ããã¯ã¢ãããã¡ã€ã«ããããŒã¿ã埩å ããŸãã
mysql -u wp_user -p wordpress_db < wordpress_backup.sql
3. å§çž®ããŒã¿ã®åŸ©å
gzipã§å§çž®ããããã¯ã¢ãããã¡ã€ã«ããªã¹ãã¢ããå Žåã¯ã以äžã®ã³ãã³ãã䜿çšããŸãã
gunzip < wordpress_backup.sql.gz | mysql -u wp_user -p wordpress_db
4. åäœç¢ºèª
埩å åŸã¯ã以äžã®ãã€ã³ãã確èªããŠãã ããã
- WordPressã®ããã·ã¥ããŒãã«ãã°ã€ã³ã§ãããã
- æçš¿ãããŒãžãæ£ãã衚瀺ããããã
- ãã©ã°ã€ã³ãããŒãã®åäœã«åé¡ããªããã
ãšã©ãŒçºçæã®å¯ŸåŠæ³
1. ããŒã¿ããŒã¹ãååšããªããšã©ãŒ
ERROR 1049 (42000): Unknown database 'wordpress_db'
解決çïŒ
ããŒã¿ããŒã¹ãäºåã«äœæããŠãããªã¹ãã¢ããŸãã
2. æš©éãšã©ãŒ
ERROR 1045 (28000): Access denied for user 'wp_user'@'localhost'
解決çïŒ
ãŠãŒã¶ãŒã«é©åãªæš©éãä»äžããŸãã
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
3. æååã察ç
æååããçºçããå Žåã¯ãæåã³ãŒãèšå®ã確èªããŸãã
ããã¯ã¢ããæïŒ
mysqldump --default-character-set=utf8 -u wp_user -p wordpress_db > wordpress_backup.sql
ãªã¹ãã¢æïŒ
mysql --default-character-set=utf8 -u wp_user -p wordpress_db < wordpress_backup.sql
ããã¯ã¢ããéçšã®èªåå
1. cronãžã§ãã«ããèªåå
ããã¯ã¢ãããèªååããããã«cronãžã§ããèšå®ããŸãã
äŸïŒæ¯æ¥åå2æã«ããã¯ã¢ãã
0 2 * * * mysqldump -u wp_user -p'wp_password' wordpress_db | gzip > /backup/wordpress_backup_$(date +\%F).sql.gz
2. ããã¯ã¢ããã®ä¿åæé管ç
å€ãããã¯ã¢ãããã¡ã€ã«ãèªåçã«åé€ããã¹ã¯ãªããäŸïŒ
find /backup/ -type f -name "*.sql.gz" -mtime +30 -exec rm {} \;
ãã®ã¹ã¯ãªããã¯ã30æ¥ä»¥äžåã®ãã¡ã€ã«ãåé€ããŸãã
ãŸãšã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãWordPressããŒã¿ããŒã¹ã®ããã¯ã¢ãããšãªã¹ãã¢æé ãå ·äœçã«è§£èª¬ããŸãããmysqldumpã³ãã³ãã掻çšããããšã§ãç°¡åãã€å®å šã«ããŒã¿ã®ä¿è·ãšåŸ©å ãå¯èœã«ãªããŸãã
6. ãã©ãã«ã·ã¥ãŒãã£ã³ã°ãšãšã©ãŒå¯Ÿç
mysqldumpã³ãã³ãã䜿çšããéã«ã¯ãç°å¢ãããŒã¿ããŒã¹ã®èšå®ã«ãã£ãŠããŸããŸãªãšã©ãŒãçºçããå¯èœæ§ããããŸãããã®ã»ã¯ã·ã§ã³ã§ã¯ããããããšã©ãŒã®åå ãšãã®è§£æ±ºæ¹æ³ã«ã€ããŠè©³ãã解説ããŸãã
1. æ¥ç¶ãšã©ãŒ
ãšã©ãŒã¡ãã»ãŒãžäŸ
ERROR 1045 (28000): Access denied for user 'user'@'localhost' (using password: YES)
åå
- ãŠãŒã¶ãŒåãŸãã¯ãã¹ã¯ãŒãã®èª€ãã
- ãŠãŒã¶ãŒã«ååãªæš©éãä»äžãããŠããªãã
解決ç
- ãŠãŒã¶ãŒåãšãã¹ã¯ãŒããæ£ããã確èªããã
- æš©éãä»äžããã
GRANT ALL PRIVILEGES ON database_name.* TO 'user'@'localhost' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
- ãã¹ã¯ãŒãã®å
¥åãèªååãããå Žåã¯ã
.my.cnf
ãã¡ã€ã«ã䜿çšããæ¹æ³ãæ€èšããŸãã
2. ããŒã¿ããŒã¹ãååšããªããšã©ãŒ
ãšã©ãŒã¡ãã»ãŒãžäŸ
ERROR 1049 (42000): Unknown database 'database_name'
åå
æå®ããããŒã¿ããŒã¹ãååšããªãã
解決ç
- ããŒã¿ããŒã¹ãäœæããŸãã
CREATE DATABASE database_name;
- ããŒã¿ããŒã¹åã®ã¹ãã«ãã¹ããªãã確èªããŸãã
3. æš©éäžè¶³ãšã©ãŒ
ãšã©ãŒã¡ãã»ãŒãžäŸ
mysqldump: Got error: 1044: Access denied for user 'user'@'localhost' to database 'database_name'
åå
ãŠãŒã¶ãŒã«ç¹å®ã®ããŒã¿ããŒã¹ãžã®ã¢ã¯ã»ã¹æš©éãä»äžãããŠããªãã
解決ç
- æš©éã確èªããŸãã
SHOW GRANTS FOR 'user'@'localhost';
- å¿ èŠãªæš©éãä»äžããŸãã
GRANT SELECT, LOCK TABLES, SHOW VIEW, EVENT, TRIGGER ON database_name.* TO 'user'@'localhost';
FLUSH PRIVILEGES;
4. 倧èŠæš¡ããŒã¿ããŒã¹ã®ããã¯ã¢ãããšã©ãŒ
ãšã©ãŒã¡ãã»ãŒãžäŸ
mysqldump: Error 2006: MySQL server has gone away when dumping table 'table_name'
åå
- ããŒã¿ããŒã¹ã倧èŠæš¡ãããŠæ¥ç¶ãã¿ã€ã ã¢ãŠãããã
- ãããã¯ãŒã¯ããµãŒããŒã®ãªãœãŒã¹äžè¶³ã
解決ç
- èšå®ãã¡ã€ã«ïŒ
my.cnf
ïŒã®å€æŽ
以äžã®ãã©ã¡ãŒã¿ãå¢ãããŸãã
[mysqld]
max_allowed_packet=512M
net_read_timeout=600
net_write_timeout=600
- ãªãã·ã§ã³ã掻çšãã
mysqldump --quick --single-transaction -u user -p database_name > backup.sql
ããã«ããã倧éããŒã¿ãå¹çããããã¯ã¢ããããŸãã
5. æååãã®åé¡
çç¶
- ãªã¹ãã¢åŸã«æ¥æ¬èªãªã©ã®ãã«ããã€ãæåãæååãããã
åå
ããã¯ã¢ãããŸãã¯ãªã¹ãã¢æã®æåã³ãŒãèšå®ãäžèŽããŠããªãã
解決ç
- ããã¯ã¢ããæã®æåã³ãŒãæå®
mysqldump --default-character-set=utf8 -u user -p database_name > backup.sql
- ãªã¹ãã¢æã®æåã³ãŒãæå®
mysql --default-character-set=utf8 -u user -p database_name < backup.sql
6. ãªã¹ãã¢æã®ããŒãã«éè€ãšã©ãŒ
ãšã©ãŒã¡ãã»ãŒãžäŸ
ERROR 1050 (42S01): Table 'table_name' already exists
åå
ãªã¹ãã¢å ã®ããŒã¿ããŒã¹ã«æ¢ã«ååã®ããŒãã«ãååšããã
解決ç
- ããã¯ã¢ãããã¡ã€ã«ã«ãDROP TABLE IF EXISTSããªãã·ã§ã³ãè¿œå ããŠããã¯ã¢ããããŸãã
mysqldump --add-drop-table -u user -p database_name > backup.sql
- æåã§å¯Ÿè±¡ã®ããŒãã«ãåé€ããŸãã
DROP TABLE table_name;
7. ããã¯ã«ããããã¯ã¢ãã倱æ
ãšã©ãŒã¡ãã»ãŒãžäŸ
mysqldump: Error 1227: Access denied; you need (at least one of) the SUPER privilege(s) for this operation
åå
ããŒãã«ããã¯ãçºçããæš©éãäžè¶³ããŠããã
解決ç
- ããã¯ãåé¿ãããªãã·ã§ã³ãè¿œå ããŸãã
mysqldump --single-transaction --skip-lock-tables -u user -p database_name > backup.sql
- å¿ èŠã«å¿ããŠæš©éãæ¡åŒµããŸãã
ãŸãšã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãmysqldumpã³ãã³ãã䜿çšããéã«çºçãããããšã©ãŒã®åå ãšãã®å¯ŸåŠæ³ã«ã€ããŠè§£èª¬ããŸããããããã®ãã©ãã«ã·ã¥ãŒãã£ã³ã°æé ãææ¡ããããšã§ãäžãäžã®åé¡ã«ãè¿ éã«å¯Ÿå¿ã§ããããã«ãªããŸãã
7. èªååãšããã¯ã¢ããæŠç¥ã®æ§ç¯
mysqldumpã³ãã³ãã掻çšããããŒã¿ããŒã¹ã®ããã¯ã¢ããã¯ãã·ã¹ãã ã®å®å šæ§ãé«ããããã«æ¬ ãããŸããããã®ã»ã¯ã·ã§ã³ã§ã¯ãããã¯ã¢ããã®èªååãšæŠç¥çãªç®¡çæ¹æ³ã«ã€ããŠè§£èª¬ããŸãã
1. èªååã®ã¡ãªãã
ããã¯ã¢ããèªååã®éèŠæ§
- ãã¥ãŒãã³ãšã©ãŒã®åé¿ïŒ æåæäœã«ãããã¹ãé²ããŸãã
- å®æçãªä¿è·ïŒ èšå®ããã¹ã±ãžã¥ãŒã«ã§ç¢ºå®ã«ããã¯ã¢ãããå®è¡ãããŸãã
- 埩æ§æéã®ççž®ïŒ é害çºçæã«ææ°ããŒã¿ãããã«åŸ©å ã§ããŸãã
掻çšã·ããªãª
- ãµã€ãæŽæ°åã®ããã¯ã¢ããã
- æ¯æ¥ã»æ¯é±ã®å®æããã¯ã¢ããã
- ãµãŒããŒã¡ã³ããã³ã¹ãã¢ããã°ã¬ãŒãæã®ããŒã¿ä¿è·ã
2. cronãžã§ãã«ããå®æããã¯ã¢ããèšå®
åºæ¬çãªcronèšå®äŸ
- cronãžã§ãã®ç·šéãéå§ããŸãã
crontab -e
- 以äžã®ã¹ã±ãžã¥ãŒã«èšå®ãè¿œå ããŸãã
äŸïŒæ¯æ¥åå2æã«ããã¯ã¢ãããååŸ
0 2 * * * mysqldump -u user -p'password' database_name | gzip > /backup/backup_$(date +\%F).sql.gz
èšå®ã®ãã€ã³ã
- ãã¹ã¯ãŒãã®ç®¡çïŒ ã³ãã³ãå ã§çŽæ¥æå®ããå Žåã¯ãã¯ã©ãŒãã§å²ã¿ãŸãã
- ãã¡ã€ã«åã«æ¥ä»ãä»å ïŒ $(date +\%F) ã¯ãYYYY-MM-DDãã®åœ¢åŒã§æ¥ä»ãä»ãã䟿å©ãªæ¹æ³ã§ãã
- å§çž®ïŒ gzipã䜿ãããšã§ãã¹ãã¬ãŒãžå®¹éãç¯çŽããŸãã
3. å€ãããã¯ã¢ããã®èªååé€
é·æéã«ããã£ãŠããã¯ã¢ãããã¡ã€ã«ãä¿åããŠãããšããã£ã¹ã¯å®¹éãå§è¿«ããå¯èœæ§ããããŸããããã§ãäžå®æéãéããããã¯ã¢ãããèªååé€ããèšå®ãè¡ããŸãã
ãã¡ã€ã«åé€ã¹ã¯ãªããäŸ
find /backup/ -type f -name "*.sql.gz" -mtime +30 -exec rm {} \;
ã³ãã³ãã®è§£èª¬
- find /backup/ïŒããã¯ã¢ãããã©ã«ãå ãæ€çŽ¢ããŸãã
- -type fïŒãã¡ã€ã«ã®ã¿ã察象ã«ããŸãã
- -name “*.sql.gz”ïŒæ¡åŒµåã.sql.gzã®ãã¡ã€ã«ãæ¢ããŸãã
- -mtime +30ïŒ30æ¥ä»¥äžåã®ãã¡ã€ã«ã察象ã«ããŸãã
- -exec rm {} \;ïŒèŠã€ãã£ããã¡ã€ã«ãåé€ããŸãã
4. ããã¯ã¢ããã®ãªã¢ãŒãä¿å
ã»ãã¥ãªãã£ãšãªã¹ã¯ç®¡çã®åŒ·å
ããŒã«ã«ãµãŒããŒã ãã§ãªãããªã¢ãŒããµãŒããŒãã¯ã©ãŠãã¹ãã¬ãŒãžã«ããã¯ã¢ãããä¿åããããšã§çœå®³å¯Ÿçã匷åã§ããŸãã
SCPã䜿çšãã転éäŸ
scp /backup/backup_$(date +\%F).sql.gz user@remote_host:/remote/backup/
rsyncã«ããå¢åããã¯ã¢ããäŸ
rsync -avz /backup/ user@remote_host:/remote/backup/
ã¯ã©ãŠãã¹ãã¬ãŒãžãžã®ã¢ããããŒãäŸ
AWS CLIã䜿ã£ãŠS3ãã±ããã«ã¢ããããŒãããå ŽåïŒ
aws s3 cp /backup/backup_$(date +\%F).sql.gz s3://my-bucket-name/
5. ã€ã³ã¯ãªã¡ã³ã¿ã«ããã¯ã¢ããæŠç¥
倧èŠæš¡ããŒã¿ããŒã¹ã®å Žåããã«ããã¯ã¢ããã¯æéãšãªãœãŒã¹ãæ¶è²»ããŸãããã®ãããã€ã³ã¯ãªã¡ã³ã¿ã«ããã¯ã¢ããã䜵çšããããšã§å¹çåãå³ããŸãã
binlogãå©çšããå¢åããã¯ã¢ãã
- ãã€ããªãã°ã®æå¹å
my.cnf
ã«ä»¥äžãè¿œå ïŒ
[mysqld]
log_bin=mysql-bin
expire_logs_days=10
- ãã€ããªãã°ã®ããã¯ã¢ãã
mysqlbinlog mysql-bin.000001 > binlog_backup.sql
- ãªã¹ãã¢æé
mysql -u user -p database_name < binlog_backup.sql
6. ã»ãã¥ãªãã£ãšããŒã¿ä¿è·å¯Ÿç
1. æå·åã«ããä¿è·
ããã¯ã¢ãããã¡ã€ã«ãæå·åããŠå®å šæ§ãé«ããŸãã
äŸïŒgpgã䜿çšããæå·å
gpg --output backup.sql.gz.gpg --encrypt --recipient user@example.com backup.sql.gz
2. ãã¹ã¯ãŒãä¿è·ä»ãã¢ãŒã«ã€ã
zip -e backup.zip backup.sql.gz
3. ã¢ã¯ã»ã¹æš©éã®èšå®
ããã¯ã¢ãããã£ã¬ã¯ããªã®ã¢ã¯ã»ã¹æš©ãå¶éããŸãã
chmod 700 /backup/
ãŸãšã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãmysqldumpã³ãã³ãã掻çšããããã¯ã¢ããã®èªååãšæŠç¥ç管çæ¹æ³ã«ã€ããŠè§£èª¬ããŸãããå®æããã¯ã¢ããããªã¢ãŒãä¿åãã€ã³ã¯ãªã¡ã³ã¿ã«ããã¯ã¢ãããçµã¿åãããããšã§ãããŒã¿ã®å®å šæ§ãå€§å¹ ã«åäžãããããšãã§ããŸãã
8. ãããã質åïŒFAQïŒ
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãmysqldumpã³ãã³ãã«é¢ããŠããå¯ãããã質åãšãã®è§£æ±ºçããŸãšããŸãããå®è·µçãªãã©ãã«è§£æ±ºã®ãã³ããšããŠã掻çšãã ããã
1. mysqldumpã®å®è¡é床ãéãããã«ã¯ïŒ
Q. ããã¯ã¢ãããé ãåå ã¯äœã§ããïŒ
A. ããŒã¿ããŒã¹ãµã€ãºã倧ããå ŽåãããŒãã«ããã¯ã«ãã£ãŠåŠçãé ããªãããšããããŸãã
解決ç
- ãªãã·ã§ã³ãæé©åãã
mysqldump --single-transaction --quick -u user -p database > backup.sql
- –single-transactionïŒãã©ã³ã¶ã¯ã·ã§ã³ã䜿ããäžè²«æ§ãä¿ã¡ã€ã€ããã¯ãåé¿ã
- –quickïŒã¡ã¢ãªäœ¿çšéãæãã€ã€ãäžè¡ãã€ããŒã¿ãåŠçã
- ãã±ãããµã€ãºãæ¡åŒµãã
èšå®ãã¡ã€ã«ïŒmy.cnf
ïŒãç·šéïŒ
max_allowed_packet=512M
- 䞊ååŠçã®æŽ»çš
è€æ°ã®ããŒãã«ã䞊ååŠçã§ããã¯ã¢ããããããŒã«ïŒäŸãã°mydumper
ïŒãå©çšããŸãã
2. ããã¯ã¢ãããã¡ã€ã«ãå§çž®ããŠä¿åããã«ã¯ïŒ
Q. ããŒã¿ããŒã¹ã倧ãããã¹ãã¬ãŒãžå®¹éãç¯çŽãããå Žåã¯ïŒ
A. gzipã䜿çšããŠããã¯ã¢ãããå§çž®ãããšãã¡ã€ã«ãµã€ãºãåæžã§ããŸãã
解決ç
mysqldump -u user -p database | gzip > backup.sql.gz
ãã®æ¹æ³ã§ã¯ãå§çž®çãé«ããªããã¹ãã¬ãŒãžå¹çãåäžã§ããŸãã
3. ãªã¹ãã¢æã®ããŒã¿ç«¶åãé²ãã«ã¯ïŒ
Q. ããŒã¿ããŒã¹ãªã¹ãã¢æã«æ¢åããŒã¿ãšç«¶åããå¯èœæ§ã¯ãããŸããïŒ
A. ããŒãã«ãããŒã¿ãéè€ããŠãããšç«¶åãçºçããããšããããŸãã
解決ç
- æ¢åããŒã¿ãåé€ããŠãªã¹ãã¢ããå Žå
mysqldump --add-drop-table -u user -p database > backup.sql
ãã®ãªãã·ã§ã³ã¯ãããŒãã«äœæåã«æ¢åããŒãã«ãåé€ããŸãã
- æ¢åããŒã¿ãä¿æãããŸãŸã€ã³ããŒãããå Žå
mysql -u user -p database < backup.sql
æ¡ä»¶ãæå®ããŠç¹å®ããŒã¿ã®ã¿äžæžãããå Žåã¯ã--replace
ãªãã·ã§ã³ãæ€èšããŠãã ããã
4. ç°ãªããµãŒããŒéã§ããŒã¿ã移è¡ããã«ã¯ïŒ
Q. å¥ã®ãµãŒããŒã«ããŒã¿ã移ãããå Žåãäœã泚æããã°ããã§ããïŒ
A. æåã³ãŒããããŒãžã§ã³ã®éãã«ããäºææ§åé¡ã«æ³šæãå¿ èŠã§ãã
解決ç
- ãšã¯ã¹ããŒãæã®æåã³ãŒããæå®
mysqldump --default-character-set=utf8 -u user -p database > backup.sql
- ãªã¹ãã¢å ã®æåã³ãŒãèšå®ã確èª
mysql --default-character-set=utf8 -u user -p database < backup.sql
- ããŒãžã§ã³äºææ§ã確ä¿ããå Žå
mysqldump --compatible=mysql40 -u user -p database > backup.sql
ãã®ãªãã·ã§ã³ã¯å€ãããŒãžã§ã³ãšã®äºææ§ã確ä¿ããŸãã
5. mysqldumpã§äžéšã®ããŒã¿ã®ã¿ããã¯ã¢ããã§ããŸããïŒ
Q. ç¹å®ã®ããŒã¿ã®ã¿ããã¯ã¢ããããæ¹æ³ã¯ãããŸããïŒ
A. --where
ãªãã·ã§ã³ã䜿çšãããšãæ¡ä»¶ä»ãã®ããŒã¿æœåºãå¯èœã§ãã
解決ç
mysqldump -u user -p database --tables table_name --where="created_at >= '2023-01-01'" > filtered_backup.sql
ãã®ã³ãã³ãã§ã¯ã2023幎1æ1æ¥ä»¥éã«äœæãããããŒã¿ã®ã¿ãããã¯ã¢ããããŸãã
6. ãªã¹ãã¢æã«æååãããå Žåã®å¯ŸåŠæ³ã¯ïŒ
Q. ãªã¹ãã¢åŸã«æ¥æ¬èªãæååãããåå ã¯ïŒ
A. ããã¯ã¢ããæãšãªã¹ãã¢æã®æåã³ãŒãèšå®ãäžèŽããŠããªãå¯èœæ§ããããŸãã
解決ç
- ããã¯ã¢ããæã®æåã³ãŒãæå®
mysqldump --default-character-set=utf8 -u user -p database > backup.sql
- ãªã¹ãã¢æã®æåã³ãŒãæå®
mysql --default-character-set=utf8 -u user -p database < backup.sql
æåã³ãŒããçµ±äžããããšã§æååããé²ããŸãã
7. ããã¯ã¢ããã倱æããå Žåã®äžè¬çãªåå ã¯ïŒ
Q. mysqldumpãéäžã§åæ¢ããå Žåãäœãåé¡ã§ããïŒ
A. ããŒã¿ããŒã¹ã®ãµã€ãºãèšå®ãæ¥ç¶ã¿ã€ã ã¢ãŠããåå ãšãªãããšãå€ãã§ãã
解決ç
- ã¡ã¢ãªèšå®ã調æŽïŒ
max_allowed_packet=512M
- ããã¯ãåé¿ãããªãã·ã§ã³ã䜿çšïŒ
mysqldump --single-transaction --skip-lock-tables -u user -p database > backup.sql
- ããŒã¿ãåå²ããŠãšã¯ã¹ããŒãïŒ
mysqldump -u user -p database table_name > table_backup.sql
ããŒãã«åäœã§ãšã¯ã¹ããŒãããããšã§è² è·ã軜æžããŸãã
ãŸãšã
ãã®ã»ã¯ã·ã§ã³ã§ã¯ãmysqldumpã³ãã³ãã«é¢ãããããã質åãšãã®è§£æ±ºçã«ã€ããŠè§£èª¬ããŸãããåºæ¬çãªäœ¿ãæ¹ãããã©ãã«ã·ã¥ãŒãã£ã³ã°ãŸã§ãã«ããŒããŠãããããmysqldumpã䜿ãããªãéã®åèã«ããŠãã ããã
9. ãŸãšã
ãããŸã§ã®ã»ã¯ã·ã§ã³ã§ã¯ãmysqldumpã³ãã³ãã®åºæ¬ããå¿çšãŸã§ãå¹ åºã解説ããŠããŸãããæ¬ã»ã¯ã·ã§ã³ã§ã¯ãèšäºã®å 容ãæ¯ãè¿ããmysqldumpã掻çšããéã®ãã€ã³ããå確èªããŸãã
1. mysqldumpã³ãã³ãã®åœ¹å²ãšç¹åŸŽ
mysqldumpã¯ãMySQLããŒã¿ããŒã¹ã®ããã¯ã¢ããã移è¡ã«æ¬ ãããªãããŒã«ã§ããããŒã¿ã®å®å šæ§ã確ä¿ããçœå®³åŸ©æ§ãéçºç°å¢ãžã®è€è£œãªã©ãå€ç®çã«å©çšã§ããŸãã
äž»ãªç¹åŸŽ
- æ±çšæ§ïŒ åäžãŸãã¯è€æ°ã®ããŒã¿ããŒã¹ããšã¯ã¹ããŒãå¯èœã
- æè»æ§ïŒ ããŒãã«åäœãæ¡ä»¶ä»ãã®ããã¯ã¢ãããå¯èœã
- äºææ§ïŒ æåã³ãŒããå€ãããŒãžã§ã³ãžã®å¯Ÿå¿ãªãã·ã§ã³ãå å®ã
ãããã®æ©èœãç解ããé©åã«çµã¿åãããããšã§ãå®å šãã€å¹ççãªããŒã¿ç®¡çãå®çŸã§ããŸãã
2. åºæ¬çãªäœ¿ãæ¹ãšå¿çšãã¯ããã¯
åºæ¬ã®ããã¯ã¢ãããšãªã¹ãã¢
mysqldumpã¯ã以äžã®ã·ã³ãã«ãªã³ãã³ãã§ããã¯ã¢ãããšåŸ©å
ãå¯èœã§ãã
ããã¯ã¢ããäŸïŒ
mysqldump -u user -p database > backup.sql
ãªã¹ãã¢äŸïŒ
mysql -u user -p database < backup.sql
䟿å©ãªãªãã·ã§ã³ã®æŽ»çš
- –single-transactionïŒ äžè²«æ§ãä¿ã¡ã€ã€ããã¯ãåé¿ã
- –quickïŒ ã¡ã¢ãªè² è·ã軜æžããªãã倧èŠæš¡ããŒã¿ãå¹ççã«ããã¯ã¢ããã
- –routines ãš –triggersïŒ ã¹ãã¢ãããã·ãŒãžã£ãããªã¬ãŒãå«ãããšã¯ã¹ããŒããå¯èœã
ãªãã·ã§ã³ãé©åã«æŽ»çšããããšã§ãããŒã¿éãç°å¢ã«å¿ããæè»ãªå¯Ÿå¿ãå¯èœã«ãªããŸãã
3. å®è·µçãªæŽ»çšäŸ
WordPressã®ããã¯ã¢ãããšãªã¹ãã¢
å®éã®äºäŸãšããŠãWordPressãµã€ãã®ããŒã¿ããŒã¹ç®¡çãäŸã«è§£èª¬ããŸããã
- ããã¯ã¢ããïŒ ãµã€ãã®æŽæ°ã移è¡åã«ããŒã¿ããŒã¹ãä¿åã
- ãªã¹ãã¢ïŒ ãµã€ã埩æ§ãéçºç°å¢ãžã®è€è£œã§æŽ»çšã
ç¹å®ã·ã¹ãã ãžã®å¿çšäŸãåèã«ããã°ãmysqldumpã®å®è·µåãããã«åäžããŸãã
4. ãã©ãã«ã·ã¥ãŒãã£ã³ã°ãšèªååã®éèŠæ§
ãšã©ãŒå¯Ÿçãšãã©ãã«ã·ã¥ãŒãã£ã³ã°
mysqldumpã§ã¯ãæ¥ç¶ãšã©ãŒãæååããæš©éäžè¶³ãªã©ã®ãã©ãã«ãçºçããããšããããŸãã
- ãšã©ãŒã¡ãã»ãŒãžã確èªããé©åãªå¯ŸåŠæ³ãçŽ æ©ãå®è·µã
- æåã³ãŒãããã±ãããµã€ãºã®èšå®èª¿æŽã«ããã倧èŠæš¡ããŒã¿ãžã®å¯Ÿå¿åã匷åã
èªååã«ããå¹çåãšå®å šæ§åäž
cronãžã§ãã䜿ã£ãå®æããã¯ã¢ããã®èšå®ãããªã¢ãŒããµãŒããŒãžã®è»¢éãå€ãããã¯ã¢ããã®èªååé€ãçµã¿åãããããšã§ãããŒã¿ä¿è·ã®å¹çãããã«åäžã§ããŸãã
5. ä»åŸã®ããŒã¿ç®¡çã«åããŠ
ããã¯ã¢ããæŠç¥ã®æé©å
- ãã«ããã¯ã¢ãããšã€ã³ã¯ãªã¡ã³ã¿ã«ããã¯ã¢ããã®äœµçšïŒ å¹ççãªéçšãç®æãã
- ãªã¢ãŒãä¿åãšæå·åã®æ¡çšïŒ ããŒã¿æŒæŽ©ãçœå®³å¯Ÿçã®åŒ·åã
mysqldump以å€ã®ããŒã«ãšã®é£æº
- Percona XtrabackupïŒ é«éãªããã¯ã¢ãããšåŸ©å ããµããŒãã
- mydumperïŒ äžŠååŠçã«ããé«éãšã¯ã¹ããŒããå®çŸã
ãããã®ããŒã«ãç¶æ³ã«å¿ããŠäœ¿ãåããããšã§ãmysqldumpãè£å®ããªããããŒã¿ç®¡çã®æé©åãå³ãããšãã§ããŸãã
6. ãããã«
mysqldumpã³ãã³ãã¯ãããŒã¿ããŒã¹ã®ç®¡çãä¿è·ã匷åããããã®åŒ·åãªããŒã«ã§ããåºæ¬çãªæäœããé«åºŠãªãªãã·ã§ã³ãŸã§ãç解ããããã¯ã¢ããæŠç¥ãèªååããããšã§ãã·ã¹ãã éçšã®å¹çãšå®å šæ§ãå€§å¹ ã«åäžãããããšãã§ããŸãã
æ¬èšäºã§è§£èª¬ããå 容ãåèã«ããã²mysqldumpãå®è·µçã«æŽ»çšããå®å¿ã»å®å šãªããŒã¿ç®¡çãå®çŸããŠãã ããã