dongwu9647 2018-03-30 15:09
浏览 41
已采纳

laravel中的数据库连接

i can't find why laravel doesn't connect to my database, i think however my configuration is right. the error i got is "SQLSTATE[HY000] [1045] Access denied for user 'homestead'@'localhost' (using password: YES) " Here is my .env

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=chat
DB_USERNAME=root
DB_PASSWORD=root

and my database.php:

      'default' => env('DB_CONNECTION', 'mysql'),

     'mysql' => [
        'driver' => 'mysql',
        'host' => env('DB_HOST', '127.0.0.1'),
        'port' => env('DB_PORT', '3306'),
        'database' => env('DB_DATABASE', 'forge'),
        'username' => env('DB_USERNAME', 'forge'),
        'password' => env('DB_PASSWORD', ''),
        'unix_socket' => env('DB_SOCKET', ''),
        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
        'prefix' => '',
        'strict' => true,
        'engine' => null,
      ],

did i miss something ?

  • 写回答

2条回答 默认 最新

  • douganbi7686 2018-03-30 15:34
    关注

    Try to replace

        'charset' => 'utf8mb4',
        'collation' => 'utf8mb4_unicode_ci',
    

    with

        'charset' => 'utf8',
        'collation' => 'utf8_unicode_ci',
    

    and then execute, from your project root:

    php artisan cache:clear
    

    Let me know what you get.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout
  • ¥15 Android studio AVD启动不了
  • ¥15 陆空双模式无人机怎么做
  • ¥15 想咨询点问题,与算法转换,负荷预测,数字孪生有关
  • ¥15 C#中的编译平台的区别影响
  • ¥15 软件供应链安全是跟可靠性有关还是跟安全性有关?
  • ¥15 电脑蓝屏logfilessrtsrttrail问题
  • ¥20 关于wordpress建站遇到的问题!(语言-php)(相关搜索:云服务器)
  • ¥15 【求职】怎么找到一个周围人素质都很高不会欺负他人,并且未来月薪能够达到一万以上(技术岗)的工作?希望可以收到写有具体,可靠,已经实践过了的路径的回答?
  • ¥15 Java+vue部署版本反编译