Laravel Homestead-MySQL默认凭据和数据库 [英] Laravel Homestead- MySQL default credentials and database

查看:269
本文介绍了Laravel Homestead-MySQL默认凭据和数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了Laravel并试图运行artisan migration命令,但是却出现了错误[PDOException] SQLSTATE [HY000] [2002]连接被拒绝. 我不确定Homestead如何设置数据库.所以我得到了以下问题. 是由工匠自动创建的默认数据库迁移还是Homestead?如果是,名称是什么? 如果不是默认情况下创建的,是否应该在运行迁移之前创建? 我尝试通过使用ssh连接到Homestead VM,然后运行MySQL来登录到MySQL数据库.但是,对于用户名流浪汉,霍姆斯特德和伪造用户,我收到错误消息用户拒绝访问....".默认凭证是什么? 我知道创建MySQL数据库不是Laravel教程的范围;因此,如果任何人都可以回答这些问题并为我指出正确的方向,将会很有帮助.谢谢.

I have setup Laravel and trying to run the artisan migrate command however I am getting the error [PDOException] SQLSTATE[HY000] [2002] Connection refused. I am not sure how db is setup in Homestead. So I got the below questions. Is default database created automatically by artisan migrate or Homestead? If it is, what is the name? If its not created by default, should we create before running migration? I tried loggin 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. Thanks.

推荐答案

Homestead随附一个名为homestead的默认数据库.您的应用可以选择挂接到该数据库,或者您必须手动创建一个新数据库.您可以使用GUI(如Mac上的Sequel Pro),也可以通过Vagrant在命令行中执行它.

Homestead comes with a default database called homestead. Your app can either choose to hook into that database, or you will have to go and make a new database manually. You can either use a GUI (like Sequel Pro on Mac) or perform it via the command line through 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;

然后您可以照常迁移数据库php artisan migrate.

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

如果您需要使用Postgres进行此操作,则非常相似.

If you need to do this with Postgres instead, it's pretty similar.

// 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 Homestead-MySQL默认凭据和数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆