I have setup Laravel and trying to run the artisan migrate command however I am getting the error below

[PDOException] SQLSTATE[HY000] [2002] Connection refused.

I am not sure how db is setup in Homestead. So I got the below questions.

  1. 默认数据库是由artisan migrate还是Homestead自动创建的?
  2. 如果是,它的名字是什么?
  3. 如果它不是默认创建的,我们应该在运行迁移之前创建它吗?

I tried logging in to MySQL db by connecting to Homestead VM using ssh and then running MySQL. However I get error Access denied for user.... for user name vagrant, Homestead and forge.

What is the default credentials? I understand that creating MySQL db is out of the scope of Laravel tutorial; So it would be helpful if anyone can answer these questions and point me in right direction.

推荐答案

Homestead附带了一个名为homestead的默认数据库.你的应用程序可以 Select 连接到该数据库,或者你必须手动创建一个新数据库.您可以使用GUI(比如Mac上的Sequel Pro),也可以通过Vagrant通过命令行执行.

// SSH into the box
vagrant ssh

// Connect to MySQL as the homestead user (password is: secret)
mysql -u homestead -p

// Create a new database in MySQL
CREATE DATABASE your_app_name;

// Leave MySQL
exit;

You can then migrate the database as usual, php artisan migrate.

如果您需要使用postgres来执行此操作,则情况非常相似.

// Connect to Postgres (password is: secret)
psql -U homestead -h localhost

// Create a new database in Postgres
CREATE DATABASE your_app_name;

// Leave Postgres
\q

Laravel相关问答推荐

为什么只删除了最后一个Like,而没有删除选中的?

Laravel 获取具有多对多关系的中间表数据

为什么 laravel 模型会重复一组数据以及如何(如果可能)只有一组数据?

上传时Laravel正在旋转图像

Carbon现在时间错了

SQLSTATE [HY000]:一般错误:1005 无法创建表 - Laravel 4

Laravel 5 文件下载:stream() 或 download()

在 AWS 上找不到 Laravel 5 类Collective\Html\HtmlServiceProvider

Web 服务器如何处理请求?

Laravel 初学者的良好开端

将图标添加到 Laravelcollective 提交按钮

安装后在 Lumen 中找不到页面

如何在 laravel 中使用 GROUP_CONCAT

Laravel 迁移 - 删除列

Laravel 的 toSql() 方法是否会屏蔽 id? (列值被问号替换)

Laravel 4:将什么作为参数传递给 Url 类?

在 Laravel 4 中使用 HTML 占位符

Carbon解析到 ISO8601

如果在 Laravel 5.1 中找不到路由,则显示 404 页面

使用迁移更改表 Laravel 5