dockerÔËÐÐmysqlÔõôÉèÖÃ
ÔÚ docker ÖÐÉèÖà mysql Éæ¼°ÒÔÏ°취£º½¨Éè»ùÓÚ mysql ¹Ù·½¾µÏñµÄ docker ¾µÏñ¡£Æô¶¯ÈÝÆ÷£¬²¢Ö¸¶¨ mysql ¸ùÃÜÂë¡¢Êý¾Ý¿âÃû³ÆºÍ¶Ë¿ÚÓ³É䡣ʹÓà docker exec ÏÂÁîÅþÁ¬µ½ÈÝÆ÷£¬²¢Ê¹Óà mysql ÏÂÁîÐнçÃæ¾ÙÐÐÉèÖá£
Docker ÖÐÔËÐÐ MySQL µÄÉèÖÃ
ÔõÑùÉèÖà Docker ÖÐµÄ MySQL£¿
ÔÚ Docker ÖÐÉèÖà MySQL Ö÷ÒªÉæ¼°Èý¸öÒªº¦°ì·¨£º
1. ½¨Éè Docker ¾µÏñ
½¨ÉèÒ»¸ö»ùÓÚ MySQL ¹Ù·½¾µÏñµÄ Docker ¾µÏñ¡£ÄúÐèÒªÖ¸¶¨ËùÐèµÄ MySQL °æ±¾£¬ÀýÈ磺
docker build -t my-mysql-image .
µÇ¼ºó¸´ÖÆ
2. Æô¶¯²¢ÉèÖÃÈÝÆ÷
ʹÓý¨ÉèµÄ¾µÏñÆô¶¯Ò»¸ö Docker ÈÝÆ÷£¬²¢Ö¸¶¨ÐëÒªÉèÖãº
docker run -d --name my-mysql-container \ -e MYSQL_ROOT_PASSWORD=your_password \ -e MYSQL_DATABASE=your_database \ -p 3306:3306 \ my-mysql-image
µÇ¼ºó¸´ÖÆ
ÆäÖУº
-e MYSQL_ROOT_PASSWORD ÉèÖà MySQL root Óû§µÄÃÜÂë¡£
-e MYSQL_DATABASE ½¨ÉèÒ»¸öÃûΪ your_database µÄÊý¾Ý¿â¡£
-p 3306:3306 ½«ÈÝÆ÷ÄÚµÄ MySQL ¶Ë¿ÚÓ³Éäµ½Ö÷»úÉ쵀 3306 ¶Ë¿Ú¡£
3. ÅþÁ¬µ½ÈÝÆ÷
ʹÓà docker exec ÏÂÁîÅþÁ¬µ½ÈÝÆ÷£¬²¢Ê¹Óà MySQL ÏÂÁîÐнçÃæ¾ÙÐÐÉèÖãº
docker exec -it my-mysql-container bash mysql -u root -p
µÇ¼ºó¸´ÖÆ
Ïêϸ˵Ã÷£º
ÇéÐαäÁ¿£ºÄú¿ÉÒÔÔÚÆô¶¯ Docker ÈÝÆ÷ʱָ¶¨ÇéÐαäÁ¿£¬ÒÔÉèÖà MySQL ЧÀÍÆ÷£¬ÀýÈç¸ùÃÜÂëºÍËùÐèÊý¾Ý¿âµÄÃû³Æ¡£
¶Ë¿ÚÓ³É䣺Äú¿ÉÒÔʹÓà -p ±ê¼Ç½«ÈÝÆ÷ÄڵĶ˿ÚÓ³Éäµ½Ö÷»úÉϵĶ˿ڣ¬Õ⽫ÔÊÐíÄú´ÓÖ÷ʱ»ú¼û MySQL¡£
MySQL ÏÂÁîÐнçÃ棺ÅþÁ¬µ½ÈÝÆ÷ºó£¬Äú¿ÉÒÔʹÓà MySQL ÏÂÁîÐнçÃæ¾ÙÐнøÒ»²½ÉèÖã¬ÀýÈ罨ÉèÓû§¡¢ÊÚÓèȨÏÞºÍÅÌÎÊÊý¾Ý¡£
ͨ¹ý×ñÕÕÕâЩ°ì·¨£¬Äú¿ÉÒÔÔÚ Docker ÖÐÀÖ³ÉÉèÖúÍÔËÐÐ MySQL¡£
ÒÔÉϾÍÊÇdockerÔËÐÐmysqlÔõôÉèÖõÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡