Laravel PDOException SQLSTATE[HY000] [1049] Unknown database 'forge'

后端 未结 23 2136
醉酒成梦
醉酒成梦 2020-12-25 11:51

I am using Laravel to connect to MySQL database.

I got this exception:

PDOException
SQLSTATE[HY000] [1049] Unknown database \'forge\'
相关标签:
23条回答
  • 2020-12-25 12:22

    In my particular case, I finally realised that my phpMyAdmin was using port 3308 while Laravel was attempting to connect through 3306. so my advice would be to ensure you have the correct connection string!

    0 讨论(0)
  • 2020-12-25 12:23

    I had this problem for several days, it turns out if I created the db inside phpMyAdmin it wouldn't appear to Laravel, so, I created the db through MySqlWorkbench, and it worked :)

    0 讨论(0)
  • 2020-12-25 12:24

    You have to clear the cache like that (because your old configuration is in you cache file) :

    php artisan cache:clear
    

    The pdo error comes from the fact Laravel use the pdo driver to connect to mysql

    0 讨论(0)
  • 2020-12-25 12:24

    You need to modify the name of the DB in the file .env (and if need in .env.example) I solved my problem with this little correction.

    0 讨论(0)
  • 2020-12-25 12:26

    write

    php artisan config:cache 
    

    in your terminal and it will be fixed

    0 讨论(0)
  • 2020-12-25 12:28
    1. Stop the server then run php artisan cache:clear.
    2. Change .env file DB_PORT=3308 (3308 For me) mysql port
    0 讨论(0)
提交回复
热议问题