laravel SQLSTATE[HY000] [1049] 未知数据库 - 数据库已创建,但无法运行

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

SQLSTATE[HY000] [1049] Unknown database - Database created, not functioning

phpmysqllaravel

提问by green

I have this in my .env file

我的 .env 文件中有这个

    APP_ENV=local
    APP_DEBUG=true
    APP_KEY=m6twKy7Lr6KKFvVa7QgXUe78xfn08MLn

    DB_HOST=localhost
    DB_DATABASE=laravel1
    DB_USERNAME=root
    DB_PASSWORD=somepass

    CACHE_DRIVER=file
    SESSION_DRIVER=file
    QUEUE_DRIVER=sync

    MAIL_DRIVER=smtp
    MAIL_HOST=mailtrap.io
    MAIL_PORT=2525
    MAIL_USERNAME=null
    MAIL_PASSWORD=null
    MAIL_ENCRYPTION=null

And this is in my database.php

这是在我的database.php

   'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'forge'),
        'username'  => env('DB_USERNAME', 'forge'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],

The database is created and I can see it in phpMyAdmin in browser.

数据库已创建,我可以在浏览器的 phpMyAdmin 中看到它。

enter image description here

在此处输入图片说明

But when I write php artisan migrateI get this error:

但是当我写php artisan migrate我得到这个错误:

[PDOException] SQLSTATE[HY000] [1049] Unknown database 'laravel1'

[PDOException] SQLSTATE[HY000] [1049] 未知数据库“laravel1”

I have seen the answers on Laravel Migration - Says unknown database, but it is created, but that didn't helped me.

我在Laravel Migration - Says unknown database, but it is created上看到了答案 ,但这对我没有帮助。

回答by Parthapratim Neog

Try specifying the MySQL port that you are using. Might work out. I had a similar issue like this. Be sure to give the appropriate port where MySQL is installed in ur system(default is 3306).

尝试指定您正在使用的 MySQL 端口。可能会奏效。我有一个类似的问题。一定要给你的系统中安装MySQL的适当端口(默认为3306)。

'mysql' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'port'      => env('DB_PORT', '3306'),
        'database'  => env('DB_DATABASE', 'databasename'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', 'root'),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ],