0
votes

I am using Laravel 5 and I am having problems with my database conneciton:

Here is my database.php file:

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

and here is my .env file:

DB_HOST=localhost

DB_DATABASE=my_scene

DB_USERNAME=root

DB_PASSWORD=null

however when i then run "php artisan migrate" i get the error

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

I have tried php artisan cache:clear and config:cache and also reloaded my xampp controller but it has not worked.

any ideas?

3
I think it's trying with null as a string. Try DB_PASSWORD= and env('DB_PASSWORD', ''), insteadfmgonzalez
still giving me an error 1049 unknown databaseAaron Sherry
Try to unset DB_PASSWORD (remove) from .env file and set env('DB_PASSWORD', null). I've never try with a null password. I thought it was empty, nor null.fmgonzalez
still saying unknown databaseAaron Sherry

3 Answers

4
votes

Its not a connection error.

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

indicates you've successfully connected to MySQL server. but there is no database matching the name my_scene

You can create a database by using any of the following methods.

1. MySQL Command Line Utility

You just have to create a database by executing this MySQL statement in your terminal

CREATE DATABASE my_scene;

read Creating Database via terminal

2. PHPMyAdmin

If you've a MySQL GUI i.e PHPMyAdmin you can easily create a database.

Refer to this article to read more about creating databases via PHPMyAdmin

3. Laravel's Command Line Utility [Artisan]

Maybe the simplest option using Laravel's artisan utility

  1. Open Your terminal
  2. Run php artisan tinker
  3. Use the following snippet to create your database

    DB::connection()->statement('CREATE DATABASE my_scene');

0
votes

In your config file, make DB_PASSWORD equal the empty string "" and leave the DB_PASSWORD out of the .env file.

Or, you can remove the null and leave the DB_PASSWORD as empty:

DB_PASSWORD=

This will signify an empty string for the password.

0
votes

I was facing the same error and I was able to solve it.

I'm using Laravel 7 with WampServer 3.2 and I have installed two databases MySQL and Maria DB

So I created the database with MySQL using PhpMyAdmin and I was getting the 1049 error when using php artisan migrate

Then I created the database with MariaDB (using PhpMyAdmin) and the Migration was successful so Laravel was trying to connect to MariaDB database but there was no database (with the correct connection values)