Laravel Homestead- MySQL 默认凭据和数据库

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25503327/
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-08 16:42:20  来源:igfitidea点击:

Laravel Homestead- MySQL default credentials and database

laravel

提问by user859375

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.

我已经设置了 Laravel 并尝试运行 artisan migrate 命令,但是我收到错误 [PDOException] SQLSTATE[HY000] [2002] 连接被拒绝。我不确定 Homestead 中的 db 是如何设置的。所以我得到了以下问题。默认数据库是由 artisan migrate 还是 Homestead 自动创建的?如果是,它的名字是什么?如果它不是默认创建的,我们应该在运行迁移之前创建吗?我尝试通过使用 ssh 连接到 Homestead VM 然后运行 ​​MySQL 来登录 MySQL 数据库。但是,对于用户名 vagrant、Homestead 和 forge,我收到错误“用户拒绝访问....”。什么是默认凭据?我知道创建 MySQL db 超出了 Laravel 教程的范围;因此,如果有人能回答这些问题并为我指明正确的方向,那将会很有帮助。谢谢。

回答by Dwight

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.

Homestead 带有一个名为homestead. 您的应用程序可以选择挂钩到该数据库,或者您必须手动创建一个新数据库。您可以使用 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.

然后您可以像往常一样迁移数据库php artisan migrate

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

如果你需要用 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