使用工匠迁移时流明错误 [英] Lumen error when using artisan migrate

查看:146
本文介绍了使用工匠迁移时流明错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  php artisan migrate 

我收到以下错误。

  [PDOException] 
SQLSTATE [HY000] [2002]没有这样的文件或目录

如果我将'localhost'更改为'127.0.0.1',我得到这个错误:

  [PDOException] 
SQLSTATE [ HY000] [2002]连接拒绝

如果我使用:

  php artisan migrate --database =流明

我得到:

  [InvalidArgumentException] 
未配置数据库[流明]。

这是我的.env文件

  DB_CONNECTION = mysql 
DB_HOST = localhost
DB_PORT = 3306
DB_DATABASE =流明
DB_USERNAME = root
DB_PASSWORD = root

我已经看到有关堆栈溢出的其他问题,并尝试了解决方案,即配置php版本并检查到mysql的路径.sock这都没事。我正在使用完整的路径,我的PHP版本是正确的。



我正在使用MAMP,并有一个名为Lumen的数据库(目前没有表)。



使用终端创建迁移:

  php artisan make:migration --create = items create_items_table 

我正在使用php工匠服务(服务器8000)来查看我的项目,我可以看看

  MAMP已开启:
apache = 80
nginx = 80
mysql = 3306

我对我的Laravel项目使用了相同的配置,这是正常的。但是laravel确实有一个database.php文件,其中包含了所有的细节。



我希望这是足够的信息,任何帮助将不胜感激!



提前感谢



编辑:这是我的app.php文件,其余的保持不变。

  require_once __DIR __。'/ .. / vendor / autoload.php'; 

Dotenv :: load(__ DIR __。'/ .. /');


$ app = new Laravel\Lumen\Application(
realpath(__ DIR __。'/ .. /')
);

$ app-> withFacades();
$ app-> withEloquent();


解决方案

经过很多的讨论,我找到了答案。



问题是使用MAMP,mysql的pdo套接字不在php.ini文件中,并且必须包含在那里。

  [Pdo_mysql] 
;如果使用mysqlnd:内部结果集缓存的缓存数量
; http://php.net/pdo_mysql.cache_size
pdo_mysql.cache_size = 2000

;本地MySQL连接的默认套接字名称。如果为空,则使用内置的
; MySQL默认值。
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket =

包括该行修复了我所有的探头。


I'm new to Lumen and when I try to use:

php artisan migrate 

I get the following error.

[PDOException]                                    
SQLSTATE[HY000] [2002] No such file or directory  

If I change 'localhost' to '127.0.0.1' I get this error:

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

If I use:

php artisan migrate --database=Lumen

I get:

[InvalidArgumentException]        
Database [Lumen] not configured.

Here is my .env file

DB_CONNECTION=mysql
DB_HOST=localhost 
DB_PORT=3306
DB_DATABASE=Lumen
DB_USERNAME=root
DB_PASSWORD=root

I've read other questions on stack overflow and have tried the solutions i.e. configuring php versions and checking the path to mysql.sock and it's all fine. I am using the full path and my PHP version is correct.

I am using MAMP and have a Database called 'Lumen' (there are no tables at the moment).

Created a migration using terminal:

php artisan make:migration --create=items create_items_table  

I am using php artisan serve (server 8000) to view my project, which I can view.

MAMP is on:
apache=80
nginx=80
mysql=3306

I used the same configuration for my Laravel project and that is working fine. But laravel does have a database.php file which has all the details inside of it.

I hope that's enough information, any help would be much appreciated!

Thanks in advance

EDIT: This is my app.php file, the rest is left untouched.

require_once __DIR__.'/../vendor/autoload.php';

Dotenv::load(__DIR__.'/../');


$app = new Laravel\Lumen\Application(
realpath(__DIR__.'/../')
);

$app->withFacades();
$app->withEloquent();

解决方案

After a lot of fiddling about, I found the answer.

The problem was with MAMP, the pdo socket for mysql was not in the php.ini file and had to be included there.

[Pdo_mysql]
; If mysqlnd is used: Number of cache slots for the internal result set cache
; http://php.net/pdo_mysql.cache_size
pdo_mysql.cache_size = 2000

; Default socket name for local MySQL connects.  If empty, uses the built-in
; MySQL defaults.
; http://php.net/pdo_mysql.default-socket
pdo_mysql.default_socket=

Including that line fixed all my probelems.

这篇关于使用工匠迁移时流明错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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