在 MAMP 中使用 Laravel 设置 PostgreSQL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18201623/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:16:10  来源:igfitidea点击:

setup PostgreSQL with Laravel in MAMP

phppostgresqllaravelmamp

提问by Om3ga

I am using MAMP on my MAC. As it comes with MySQL by default. But now I need to use PostgreSQL in one of my project. How can I setup postgreSQL in MAMP for Laravel project?

我在我的 MAC 上使用 MAMP。因为它默认与 MySQL 一起提供。但是现在我需要在我的一个项目中使用 PostgreSQL。如何在 MAMP 中为 Laravel 项目设置 postgreSQL?

回答by Jacob Squires

Ok if you are set on using postgreSQL over mySQL that comes with MAMP you have to manually install postgreSQL on you location machine the OSX packages can be found here,

好的,如果您设置在 MAMP 附带的 mySQL 上使用 postgreSQL,则必须在您的定位机器上手动安装 postgreSQL,可以在此处找到 OSX 软件包,

If you don't want to do a full install i recommend this Postgres Appjust download an extract to your applications folder then when you launch it the port number will be displayed in the menu bar like so:

如果您不想进行完整安装,我建议您将这个Postgres 应用程序下载到您的应用程序文件夹中,然后当您启动它时,端口号将显示在菜单栏中,如下所示:

Postgres.app

Postgres.app

create a database:

创建数据库:

  1. go to menu above Click on Open psql
  2. In the command line create you database like so: CREATE DATABASE your_database_name;
  3. should return CREATE DATABASE
  1. 转到上面的菜单单击打开 psql
  2. 在命令行中创建您的数据库,如下所示: CREATE DATABASE your_database_name;
  3. 应该回来 CREATE DATABASE

Tip to exit postgreSQL CLI use \qthen ENTER

退出 postgreSQL CLI 的提示,\q然后使用ENTER

You now need to plug these settings into Laravels configuration:

您现在需要将这些设置插入 Laravel 配置中:

  1. open file: %laravel_directory%/app/config/database.php
  2. in the array replace 'default' => 'mysql',with 'default' => 'pgsql',
  3. now with the information from before edit the 'connections'array like so:

    'connections' => array(
        'pgsql' => array(
            'driver'   => 'pgsql',
            'host'     => 'localhost',
            'database' => 'your_database_name',
            'username' => '',
            'password' => '',
            'charset'  => 'utf8',
            'prefix'   => '',
            'schema'   => 'public',
        ),
    )
  4. save file

  1. 打开文件:%laravel_directory%/app/config/database.php
  2. 在数组中替换'default' => 'mysql','default' => 'pgsql',
  3. 现在使用之前的信息编辑'connections'数组,如下所示:

    'connections' => array(
        'pgsql' => array(
            'driver'   => 'pgsql',
            'host'     => 'localhost',
            'database' => 'your_database_name',
            'username' => '',
            'password' => '',
            'charset'  => 'utf8',
            'prefix'   => '',
            'schema'   => 'public',
        ),
    )
  4. 保存存档

You should now have a functioning database that Laravel can talk to.

你现在应该有一个 Laravel 可以与之通信的正常运行的数据库。

Note you do not need the username or password in database config if you are using the Postgres App.

请注意,如果您使用的是Postgres App,则在数据库配置中不需要用户名或密码。