laravelÔõôн¨Êý¾Ý¿â
laravelÊÇÒ»ÖÖ»ùÓÚphp¿ª·¢µÄweb¿ò¼Ü£¬ÓÉÓÚËüÌṩÁËÐí¶à¹¦Ð§Ç¿Ê¢µÄ¹¤¾ßºÍÀà¿â£¬Äܹ»ÉÁ¿ª·¢Õß¿ìËÙʵÏÖwebÓ¦ÓóÌÐò¡£ÆäÖУ¬Ð½¨Êý¾Ý¿âÊÇlaravelÖÐÊ®·ÖÖ÷ÒªµÄÒ»¸ö¹¦Ð§£¬±¾ÎÄÕ½«ÏÈÈÝÔõÑùÔÚlaravelÖн¨ÉèÊý¾Ý¿â¡£
ʵÏÖLaravelÖÐн¨Êý¾Ý¿âµÄÒªÁìÓÐÐí¶à£¬ÆäÖÐ×î³£ÓõľÍÊÇʹÓÃArtisanÏÂÁîÐй¤¾ßÍê³É¡£ArtisanÏÂÁîÐй¤¾ß¿ÉÒÔͨ¹ýÔËÐÐÏÂÁîphp artisanÀ´Æô¶¯£¬ËüÌṩÁËÐí¶à¹¦Ð§£¬ÈçÌìÉú´úÂ롢ɨ³ý»º´æ¡¢½¨ÉèÊý¾ÝǨáã¡¢ÌìÉú¿ØÖÆÆ÷µÈ¡£ÏÂÃæ¾ÍÊÇʹÓÃArtisanÏÂÁîÐй¤¾ß½¨ÉèÊý¾Ý¿âµÄ°ì·¨£º
°ì·¨
µÚÒ»²½£ºÉèÖÃÊý¾Ý¿âÅþÁ¬
ÔÚLaravelÖÐÉèÖÃÊý¾Ý¿âÅþÁ¬ºÜÊǼòÆÓ£¬Ö»ÐèÒªÐÞ¸Ä.envÎļþ¼´¿É¡£ÔÚ.envÎļþÖУ¬Ò»Ñùƽ³£ÇéÐÎÏÂÄãÐèÒªÐ޸ĵÄÊÇÒÔϼ¸Ï
DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD=
µÇ¼ºó¸´ÖÆ
ÆäÖУ¬DB_CONNECTIONÊÇÊý¾Ý¿âÅþÁ¬ÀàÐÍ£¬Ò»Ñùƽ³£ÇéÐÎÏÂʹÓÃmysql¼´¿É£¬DB_HOSTºÍDB_PORTÊÇÊý¾Ý¿âЧÀÍÆ÷µÄµØµãºÍ¶Ë¿ÚºÅ£¬DB_DATABASEÊÇҪн¨µÄÊý¾Ý¿âÃû³Æ£¬DB_USERNAMEºÍDB_PASSWORDÊÇÅþÁ¬Êý¾Ý¿âµÄÓû§ÃûºÍÃÜÂë¡£
µÚ¶þ²½£º½¨ÉèеÄÊý¾Ý¿â
ÔÚÍê³ÉÁË.envÎļþµÄÉèÖÃÖ®ºó£¬¿ÉÒÔʹÓÃÒÔÏÂÏÂÁîÀ´½¨ÉèÊý¾Ý¿â£º
php artisan db:create
µÇ¼ºó¸´ÖÆ
Ö´ÐÐÕâ¸öÏÂÁîºó£¬Laravel»á×Ô¶¯¼ì²â.envÎļþÖеÄÉèÖÃÐÅÏ¢£¬²¢Æ¾Ö¤ÆäÖеÄÐÅÏ¢ÔÚMySQLÊý¾Ý¿âÖн¨ÉèÒ»¸öеÄÊý¾Ý¿â¡£ÈôÊÇÒ»ÇÐÕý³££¬Ä㽫ÔÚÖÕ¶ËÉÏ¿´µ½ÀàËÆÓÚÏÂÃæµÄÊä³ö£º
Database created successfully.
µÇ¼ºó¸´ÖÆ
µÚÈý²½£º¼ì²éеÄÊý¾Ý¿âÊÇ·ñ½¨ÉèÀÖ³É
Äã¿ÉÒÔʹÓÃmysqlÏÂÁîÐй¤¾ß¼ì²âеÄÊý¾Ý¿âÊÇ·ñ½¨ÉèÀֳɡ£ÔÚÏÂÁîÐÐÖÐÊäÈëÒÔÏÂÏÂÁ
mysql -u root -p
µÇ¼ºó¸´ÖÆ
Õâ¸öÏÂÁî»áʹÓÃrootÓû§µÇ¼MySQLÊý¾Ý¿â£¬µÇ¼Àֳɺó£¬ÔÚMySQLÏÂÁîÐÐÖÐÊäÈëÒÔÏÂÏÂÁî¼ì²âÊÇ·ñ±£´æÃûΪlaravelµÄÊý¾Ý¿â£º
show databases;
µÇ¼ºó¸´ÖÆ
ÈôÊÇÒ»ÇÐÕý³££¬ÄãÓ¦¸Ã¿ÉÒÔ¿´µ½ÀàËÆÓÚÏÂÃæµÄÊä³ö£º
+--------------------+ | Database | +--------------------+ | information_schema | | laravel | | mysql | | performance_schema | | sys | +--------------------+
µÇ¼ºó¸´ÖÆ
µÚËIJ½£ºÊ¹ÓÃеÄÊý¾Ý¿â
ÔÚÍê³ÉÁËÉÏÊö°ì·¨Ö®ºó£¬ÐµÄÊý¾Ý¿âÒѾ¿ÉÒÔÔÚLaravelÓ¦ÓóÌÐòÖÐʹÓÃÁË¡£Äã¿ÉÒÔÔÚconfig/database.phpÎļþÖмì²éÊÇ·ñÀÖ³ÉÉèÖÃÁËÊý¾Ý¿âÅþÁ¬ÐÅÏ¢£º
'mysql' => [ 'driver' => 'mysql', 'url' => env('DATABASE_URL'), 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'laravel'), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', ''), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci', 'prefix' => '', 'prefix_indexes' => true, 'strict' => true, 'engine' => null, 'options' => extension_loaded('pdo_mysql') ? array_filter([ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), ]) : [], ],
µÇ¼ºó¸´ÖÆ
ÔÚ´úÂëÖУ¬env()º¯Êý»á¶ÁÈ¡.envÎļþÖеÄÇéÐαäÁ¿£¬´Ó¶ø»ñÈ¡Êý¾Ý¿âÅþÁ¬ÐÅÏ¢£¬ÈôÊÇÒ»ÇÐ׼ȷ£¬¾Í¿ÉÒÔ×îÏÈÔÚLaravelÓ¦ÓóÌÐòÖÐʹÓÃеÄÊý¾Ý¿âÁË¡£
×ܽá
ʹÓÃArtisanÏÂÁîÐй¤¾ß½¨ÉèеÄÊý¾Ý¿âºÜÊǼòÆÓ£¬Ö»ÐèҪƾ֤ÉÏÊö°ì·¨Íê³ÉÉèÖü´¿É¡£Í¨¹ýÕâƪÎÄÕ£¬ÄãÒѾÏàʶÁËÔõÑùÔÚLaravelÖн¨ÉèеÄÊý¾Ý¿â£¬ÐÅÍÐÕâ¹ØÓÚÕýÔÚѧϰLaravelµÄ¿ª·¢ÕߺÜÊÇÓÐÓ᣿ÉÊÇÇë×¢ÖØ£¬ÔÚ½¨ÉèеÄÊý¾Ý¿â֮ǰ£¬ÇëÏȱ¸·ÝÊý¾Ý£¬ÒÔÃⱬ·¢ÒâÍâÇéÐΡ£
ÒÔÉϾÍÊÇlaravelÔõôн¨Êý¾Ý¿âµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡