laravelÔõô¹Ø±Õmysql
laravel ÊÇ php ÖÐÒ»¿îºÜÊÇÊ¢ÐеĿª·¢¿ò¼Ü£¬Îª¿í´óµÄ¿ª·¢ÕßÃÇÌṩÁËһϵÁиßЧ¡¢Ò×ÓÃÇÒ¹¦Ð§¸»ºñµÄ¿ª·¢¹¤¾ß£¬ÒÔ¼°Àû±ãµÄÖ§³Öϵͳ¡£¶øÔÚ laravel µÄ¿ª·¢Àú³ÌÖУ¬ÎÒÃÇͨ³£»áʹÓà mysql ×÷ΪÊý¾Ý¿âЧÀÍ¡£¿ÉÊÇ£¬ÓÐʱ¼äÎÒÃÇ»áÐèÒª¹Øµô mysql ЧÀÍ£¬¾ÙÐÐһЩÏà¹Ø²Ù×÷¡£ÄÇô£¬±¾ÎĽ«»áΪÄúÏÈÈÝ laravel ÔõÑù¹Ø±Õ mysql¡£
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÔÚ Laravel ÖÐÉèÖúà MySQL Êý¾Ý¿âÅþÁ¬£¬È·±£Äܹ»Õý³£Ê¹Óá£ÔÚ Laravel 5.5 ¼°ÆäÒÔÉÏ°æ±¾ÖУ¬Õâ¸öÉèÖÃÎļþΪ config/database.php£¬¶øÔÚ Laravel 5.4 ¼°ÆäÒÔÏ°汾ÖУ¬Õâ¸öÉèÖÃÎļþΪ .env Îļþ¡£
Õë¶Ô config/database.php Îļþ£¬ÎÒÃÇ¿ÉÒÔÔÚ connections Êý×éÖÐÕÒµ½ mysql ÉèÖã¬Æ¾Ö¤ÐèÒª¾ÙÐÐÐ޸ģ¬³£¼ûµÄÉèÖÃÏî°üÀ¨ host¡¢port¡¢database¡¢username¡¢password µÈµÈ¡£ÀýÈ磺
'connections' => [ 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'forge'), 'username' => env('DB_USERNAME', 'forge'), 'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'strict' => true, 'engine' => null, ], ],
µÇ¼ºó¸´ÖÆ
¹ØÓÚ .env Îļþ£¬ÔòÐèÒªÔÚÆäÖÐÉèÖúà MySQL Ïà¹ØµÄÇéÐαäÁ¿£¬ÀýÈ磺
DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=homestead DB_USERNAME=homestead DB_PASSWORD=secret
µÇ¼ºó¸´ÖÆ
Ò»µ©ÅþÁ¬ÉèÖÃ׼ȷ£¬ÎÒÃÇ¿ÉÒÔͨ¹ý php artisan migrate ÏÂÁîÀ´¾ÙÐÐÊý¾Ý¿âǨáã¡£Õâ¸öÏÂÁî»áÒÀ´ÎÖ´ÐÐ database/migrations Ŀ¼ÏµÄËùÓÐǨáãÎļþ£¬½«½ç˵ºÃµÄÊý¾Ý¿â½á¹¹µ¼Èëµ½ MySQL ÖС£
ÄÇô£¬µ±ÎÒÃÇÐèÒª¹Ø±Õ MySQL ЧÀÍʱ£¬Ó¦¸ÃÔõÑù²Ù×÷ÄØ£¿×Åʵ£¬¹Ø±Õ MySQL ²¢²»ÐèÒªÌØÊâµÄ Laravel ÏÂÁî»ò API£¬¶øÊÇ¿ÉÒÔÖ±½ÓʹÓÃϵͳÏÂÁîÀ´Íê³É¡£
ÔÚ Linux ϵͳÏ£¬ÎÒÃÇ¿ÉÒÔʹÓà systemctl ÏÂÁîÀ´ÖÎÀí MySQL ЧÀÍ¡£ºÃ±È£¬Æô¶¯ MySQL ЧÀ͵ÄÏÂÁîΪ£º
sudo systemctl start mysql
µÇ¼ºó¸´ÖÆ
¶ø¹Ø±Õ MySQL ЧÀ͵ÄÏÂÁîÔòΪ£º
sudo systemctl stop mysql
µÇ¼ºó¸´ÖÆ
ËäÈ»£¬ÈôÊÇÄúʹÓõÄÊÇ Mac »ò Windows ²Ù×÷ϵͳ£¬ÄÇô¹Ø±Õ MySQL ЧÀ͵ÄÒªÁìÒ²ÊDzî±ðµÄ¡£¹ØÓÚ Mac Óû§£¬¿ÉÒÔͨ¹ýÒÔÏÂÏÂÁîÆô¶¯ºÍ¹Ø±Õ MySQL ЧÀÍ£º
sudo /usr/local/mysql/support-files/mysql.server start sudo /usr/local/mysql/support-files/mysql.server stop
µÇ¼ºó¸´ÖÆ
¹ØÓÚ Windows Óû§£¬ÔòÐèÒªÔÚЧÀÍÖÎÀíÖоÙÐÐÏà¹Ø²Ù×÷¡£ÏêϸҪÁìΪ£ºÔÚ Windows µÄËÑË÷¿òÖÐÊäÈë services.msc ÏÂÁ·¿ª¡¸Ð§ÀÍ¡¹Ò³Ã棬ÔÚÁбíÖÐÕÒµ½ MySQL ЧÀÍ£¬ÓÒ¼üÑ¡Ôñ¡¸×èÖ¹¡¹¼´¿É¡£
×ܵÄÀ´Ëµ£¬¹Ø±Õ MySQL ЧÀͲ¢²»ÊÇÌØÊâÖØ´óµÄ²Ù×÷£¬¶ø Laravel µÄʹÓÃÒÀÀµÓÚ MySQL ЧÀ͵ÄÕý³£ÔËÐС£ÈôÊÇÐèÒªÔÚ Laravel ÉϾÙÐÐÏà¹Ø²Ù×÷£¬½¨ÒéÏȱ¸·ÝºÃÊý¾Ý¿â£¬²¢¹Ø±Õ MySQL ЧÀͺóÔÙ¾ÙÐÐÐ޸ġ£ËäÈ»£¬ÔÚ¹Ø±Õ MySQL ЧÀÍÇ°£¬Ò²¿ÉÒÔʹÓà Laravel ÌṩµÄһЩ API ÅÐ¶Ï MySQL ЧÀÍÄ¿½ñÊÇ·ñÕýÔÚÔËÐУ¬ÒÔ±ãÓÚÔ½·¢Çå¾²µØ¾ÙÐÐÏà¹Ø²Ù×÷¡£
×îºó£¬×ܽáһϱ¾ÎÄËùÊöµÄ Laravel ¹Ø±Õ MySQL µÄÒªÁì¡£¹ØÓÚ Linux Óû§£¬¿ÉÒÔʹÓà systemctl ÏÂÁîÀ´ÖÎÀí MySQL ЧÀͲ¢Íê³ÉÏà¹Ø²Ù×÷£»¹ØÓÚ Mac Óû§£¬¿ÉÒÔͨ¹ý mysql.server ÏÂÁîÀ´¹Ø±Õ MySQL ЧÀÍ£»¹ØÓÚ Windows Óû§£¬ÔòÐèÒªÔÚЧÀÍÖÎÀíÖоÙÐнøÒ»²½²Ù×÷¡£ÎÞÂÛÄÄÖÖÒªÁ죬½¨ÒéÏȱ¸·ÝºÃÊý¾Ý¿â£¬²¢¹Ø±Õ MySQL ЧÀͺóÔÙ¾ÙÐÐÏà¹ØÐ޸ġ£
ÒÔÉϾÍÊÇlaravelÔõô¹Ø±ÕmysqlµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡