10

I'm using laravel socialite to make facebook login, following this website: Social Logins with Socialite

as soon as I type a command in the terminal:

php artisan migrate

This shows the error:

Illuminate\Database\QueryException : SQLSTATE[HY000] [1049] Unknown database 'laravel' (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

1
  • 1
    can you post your .env file settings? Commented Sep 3, 2019 at 11:22

12 Answers 12

15

Open the .env file and edit it. Just set up correct DB credentials:

DB_CONNECTION=mysql 
DB_HOST=127.0.0.1 
DB_PORT=3306 
DB_DATABASE=          // Your Database Name
DB_USERNAME=          // Your Database Username
DB_PASSWORD=          // Your Database Password 

The DB_USERNAME should be set to root if you do not have a default username

If no password is set on the database, clear it DB_PASSWORD

After completion of .env edit must be clear cache: php artisan config:cache

After Run the migrate Artisan command: php artisan migrate

Sign up to request clarification or add additional context in comments.

2 Comments

``` DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=laravel DB_USERNAME=root DB_PASSWORD= ``` I've tried like this and still doesn't work :(((
@JohnnyJeong Did you clear the cache? Also, please check that you have created a database named laravel in server database?
11

The database called laravel cannot be found in PhpMyAdmin

Please follow these steps to solve this problem :

  1. Go to phpmyadmin in your localhost dashboard

  2. Create a database and name it laravel

  3. run the php artisan migrate CMD or Terminal of your editor

Comments

5

I had the same issue But changing localhost with 127.0.0.1 solved it for me

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

1 Comment

Thanks Hassan , were same issue but now resolved
2

Question is not about facebook login. You migration command could not establish connection with your database actually.

Check you .env file, you need to have something like this

DB_CONNECTION=mysql
DB_PORT=3306
DB_HOST=localhost
DB_DATABASE=laravel // This is line which you need to update, set here the real database name
DB_USERNAME=root
DB_PASSWORD=

If you have not file .env you can rename .env.example to .env, setup you db configs, and you will be able to migrate your tables with migrate command.

If you want to call you db as laravel, it means you forgot to create that database, first create database using command line with mysql or any application which can work with mysql (phpMyAdmin, DataGrip, phpStorm, jetbrain Db, etc)

1 Comment

You didnt read his post. It didnt work. I am at this point too. I made changes to the .env file, added the database name, cleared cache. Did not work.
1

Looks like you forgot to setup your Laravel application. You can specify database connections and other basic settings in your .env file in the root of your project.

Comments

0

At first stance this points to a problem in the .env and ./config/database.php files. In the .env file you should have something like this

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

and in ./config/database.php something like this

'mysql' => [
            'driver' => 'mysql',
            'url' => env('DATABASE_URL'),
            'host' => env('DATABASE_HOST','localhost'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DATABASE_NAME','laravel'),
            'username' => env('DATABASE_USERNAME','root'),
            'password' => env('DATABASE_PASSWORD',''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'prefix_indexes' => true,
            'strict' => true,
            'engine' => null,
            'options' => extension_loaded('pdo_mysql') ? array_filter([
                PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
            ]) : [],
        ],

If your console were showing you something like this

Database hosts array is empty. (SQL: select * from information_schema.tables where table_schema = laravel and table_name = migrations and table_type = 'BASE TABLE')

you had to ensure to have specified the host. This would've happen if you had in ./config/database.php something like this (notice that it doesn't refer 'localhost' like before)

'host' => env('DATABASE_HOST'),

Assuming all is fine here and you have the database name you want to use, then it means that your database doesn't exist. Just go to phpmyadmin, or so, and create one.

Comments

0

The issue for me was the database.php config file did not have the PORT config, so it was default to 3306, but my database used a different port. I just added the line of config to the mysql config:

'mysql' => [
'port' => env('DB_PORT', '3306')
]

Comments

0

Solution founded. I had the same problem. the reason for the problem is there is no any database called "laravel" in phpmyadmin. It may be deleted or renamed. So check whether there is a database called 'laravel'. If it's not present create database in phpmyadmin using the name,

laravel

After that run the command,

php artisan migrate

This worked for me

Comments

0

As you can see from the answers above that you need the change the name of the database in the .env file , make sure you are changing on the .env instead of .env.example file

Comments

0

php artisan route:cache

apply this command and solved my error

Comments

0

i solved the problem by writing the database name in single quotes...

DB_HOST=localhost
DB_PORT=3306
DB_DATABASE='laravel'
DB_USERNAME=root
DB_PASSWORD=

Comments

-1

I had the same issue But changing DB_HOST=127.0.0.1 to DB_HOST:localhost solved it for me

DB_HOST=localhost //DB_HOST=127.0.0.1 to DB_HOST:localhost solved
DB_PORT=3306
DB_DATABASE=laravel_multiauth
DB_USERNAME=root
DB_PASSWORD=

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.