美文网首页Laravel程序员
laravel config database

laravel config database

作者: 3275508ab630 | 来源:发表于2017-12-13 21:08 被阅读46次

database.php

default 注释翻译:

    /*
    |--------------------------------------------------------------------------
    | Default Database Connection Name
    |--------------------------------------------------------------------------
    |
    | Here you may specify which of the database connections below you wish
    | to use as your default connection for all database work. Of course
    | you may use many connections at once using the Database library.
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),
    /*
    |--------------------------------------------------------------------------
    | 默认数据库连接名称
    |--------------------------------------------------------------------------
    |
    | 在这里,您可以指定下面哪个数据库连接用作所有数据库工作的默认连接。 
    | 当然,您可以使用数据库库一次使用多个连接。
    | 
    |
    */

    'default' => env('DB_CONNECTION', 'mysql'),

个人理解:数据库的默认链接。

connections 注释翻译:

    /*
    |--------------------------------------------------------------------------
    | Database Connections
    |--------------------------------------------------------------------------
    |
    | Here are each of the database connections setup for your application.
    | Of course, examples of configuring each database platform that is
    | supported by Laravel is shown below to make development simple.
    |
    |
    | All database work in Laravel is done through the PHP PDO facilities
    | so make sure you have the driver for your particular database of
    | choice installed on your machine before you begin development.
    |
    */

    'connections' => [...],
    /*
    |--------------------------------------------------------------------------
    | 数据库连接
    |--------------------------------------------------------------------------
    |
    | 以下是为您的应用程序设置的每个数据库连接。 
    | 当然,配置Laravel支持的每个数据库平台的示例如下所示,使开发变得简单。
    | 
    |
    |
    | Laravel中的所有数据库工作都是通过PHP PDO工具完成的,
    | 因此在开始开发之前,请确保在您的计算机上安装了用于选择特定数据库的驱动程序。
    |
    |
    */

    'connections' => [...],

个人理解:数据库的默认链接。关于读写分离可以参考下面文章
作者:学院君 链接:http://laravelacademy.org/tags/读写分离

migrations 注释翻译:

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',
    /*
    |--------------------------------------------------------------------------
    | 迁移存储库表
    |--------------------------------------------------------------------------
    |
    | 该表跟踪已经为您的应用程序运行的所有迁移。 
    | 使用这些信息,我们可以确定哪个磁盘上的迁移实际上没有在数据库中运行。
    | 
    |
    */

    'migrations' => 'migrations',

个人理解:数据库迁移记录表。举个例子:

  • 有时候遇到表需要修改,比如 Users 增加新的字段,
  • 但是又不想多建一个增加字段的 migrations 迁移文件。
  • 可以把 migrations 这张迁移表的 Users 对应的记录删除,
  • 再把 Users 表删除。
  • 在原来 Users 迁移文件字段信息填上去做好修改,
  • 执行 php artisan migrate 就可以了。
  • 原来的数据可以先用工具导出来,修改完成后再导回进去。

redis 注释翻译:

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [...],
    /*
    |--------------------------------------------------------------------------
    | Redis数据库
    |--------------------------------------------------------------------------
    |
    | Redis是一个开源的,快速和高级的键值存储器, 
    | 它提供了比典型的键值系统(如APC或Memcached)更丰富的命令集。
    | Laravel可以很容易的进行挖掘。
    |
    */

    'redis' => [...],

个人理解:redis的连接配置,如果项目中的 sesstioncache 都用到了 redis,可以让它们分别存在不同的数据库里,参考我之前的文章 laravel config cache

相关文章

网友评论

    本文标题:laravel config database

    本文链接:https://www.haomeiwen.com/subject/cjgzixtx.html