laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.17k stars 10.88k forks source link

php artisan migrate error #19522

Closed mianshargeel closed 7 years ago

mianshargeel commented 7 years ago

Description:

i m running command: php artisan migrate and getting such like Exception as [Illuminate\Database\QueryException]
SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables
where table_schema = laravel3 and table_name = migrations)

Steps To Reproduce:

rossjcooper commented 7 years ago

Are you on Mac or Linux?

mianshargeel commented 7 years ago

I m on mac

sisve commented 7 years ago

Could you update this issue with your mysql version?

amadeann commented 7 years ago

If this is a fresh install, do you see the migrations table in the DB (i.e. what happens when you execute the query from the exception directly in mysql)? I had once a similar issue and it was caused by the wrong configuration of DB connection parameters (in my case it was hostname).

mianshargeel commented 7 years ago

Sisve I have already updated mysql

rossjcooper commented 7 years ago

You may have to specify a connection socket in your config or use 127.0.0.1 as your DB_HOST rather than localhost

Stack Overflow Solution

hakuno commented 7 years ago

It seems a database schema issue. Can you test without schema or whatever? By the way, does MySQL have schema like PostgreSQL?

mianshargeel commented 7 years ago

this is my config/database.php '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, ],

and this is my .env file

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

neoacevedo commented 7 years ago

For me, is a bug on artisan in all Laravel versions. I have a similar issue on Laravel 4.2 using server variables for database connection. If I configure on database.php each value with direct values, artisan works, but if I use environment or server variables, artisan displays the mentioned error.

mianshargeel commented 7 years ago

i also tried to submit all connection data(DB_name, username, pass etc) in my database.php but i did't works

znsstudio commented 7 years ago

As far as I know you can not have both .env file and environment settings done via shell.

neoacevedo commented 7 years ago
'host' =>  '127.0.0.1:3306', //or localhost
'database' =>  'forge',
'username' =>  'forge',
'password' =>  '',

Without unix_socket. In my case works for migrations and commands. Just I tried to log a server custom variable on command and it goes empty, so for .env files on >=L5 or using directly server variables I think we will need to do something like this StackOverflow question

themsaid commented 7 years ago

Looks like a configuration issue, the query you shared is for postgres grammar not MySQL, please double check your config because a fresh laravel installation works with no issues.

Closing but feel free to continue discussion.

mianshargeel commented 7 years ago

again getting thie kind of error [Illuminate\Database\QueryException]
SQLSTATE[HY000] [1049] Unknown database 'blog' (SQL: select * from information_schem
a.tables where table_schema = blog and table_name = migrations)

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

nnsdev commented 7 years ago

Your database 'blog' does not exist.

mianshargeel commented 7 years ago

NowNewStart but I created database 'blog' myself​ in mysql it is existing but when I run php artisan migrate I m getting that error, actually I m very junior in Laravel maybe I m missing something ... ?

bujashaka commented 6 years ago

I have similar issue, php artisan migrate thinks that databasse name is information_schema even i specified database name in .env and it tries to use sqlite even i have mysql specified.

kennblvnp commented 6 years ago

No one is answering this? Having the same problem.

@mianshargeel @bujashaka Have you already solved it?

kevinruscoe commented 6 years ago

@kennblvnp This error is pretty generic, there's a chance your issue is completely different.

kennblvnp commented 6 years ago

There is something weird that I noticed.

@kevdotbadger my localhost link is this: http://localhost:8888/phpmyadmin/index.php

but displayed in website phpmyadmin is: Server: localhost:8889

What does that mean?

This is my .env file by the way


> APP_NAME=Laravel
> APP_ENV=local
> APP_KEY=base64:cmB21VLopjlYMSrCrmuWlKYx22cUDUm5jbXXYBu71ks=
> APP_DEBUG=true
> APP_LOG_LEVEL=debug
> APP_URL=
> 
> DB_CONNECTION=mysql
> DB_HOST=localhost
> DB_PORT=3306
> DB_DATABASE=ppp
> DB_USERNAME=root
> DB_PASSWORD=root
> 
> BROADCAST_DRIVER=log
> CACHE_DRIVER=file
> SESSION_DRIVER=file
> SESSION_LIFETIME=120
> QUEUE_DRIVER=database
> 
> REDIS_HOST=127.0.0.1
> REDIS_PASSWORD=null
> REDIS_PORT=6379
> 
> MAIL_DRIVER=smtp
> MAIL_HOST=smtp.mailtrap.io
> MAIL_PORT=2525
> MAIL_USERNAME=null
> MAIL_PASSWORD=null
> MAIL_ENCRYPTION=null
> 
> PUSHER_APP_ID=
> PUSHER_APP_KEY=
> PUSHER_APP_SECRET=
> 
kennblvnp commented 6 years ago

What is port on 8888 and then shows up 8889? @kevdotbadger

mianshargeel commented 6 years ago

Hi sorry I didn't solve it.

On 5 Jan 2018 5:25 pm, "Kenn Blvnp" notifications@github.com wrote:

What is port on 8888 and then shows up 8889? @kevdotbadger https://github.com/kevdotbadger

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/laravel/framework/issues/19522#issuecomment-355581227, or mute the thread https://github.com/notifications/unsubscribe-auth/ATgi1NQGRFayWlgJQTNnSjkS4jTNo7KPks5tHj7fgaJpZM4NzS_M .

kennblvnp commented 6 years ago

@mianshargeel @kevdotbadger It was already answered a few scroll up.

Solution: https://stackoverflow.com/questions/27365473/mamp-with-laravel-unix-socket

Quick solution: DB_HOST=localhost;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock (at .env file)

By @rossjcooper answer

Thanks!

neoacevedo commented 6 years ago

I think for .env file on Laravel should be needed https://github.com/vlucas/phpdotenv on artisan migrations.

rossjcooper commented 6 years ago

Try changing DB_HOST in your .env to 127.0.0.1

devamit2018 commented 6 years ago

i too have same issue while installing crudbooster.

In Connection.php line 664:

SQLSTATE[HY000] [1049] Unknown database 'project1' (SQL: select * from information_schema.tables w here table_schema = project1 and table_name = migrations)

In PDOConnection.php line 47:

SQLSTATE[HY000] [1049] Unknown database 'project1'

In PDOConnection.php line 43:

SQLSTATE[HY000] [1049] Unknown database 'project1'

but migrations file are created in databse

kennblvnp commented 6 years ago

@devamit2018 u need to first create a database called project1 in phpmyadmin

devamit2018 commented 6 years ago

generally i create laravel from laragon and install crudbooster.it was working fine since crudbooster would automatically create database after changing in env file..

kennblvnp commented 6 years ago

I think @devamit2018 you should report this issue to: https://github.com/crocodic-studio/crudbooster

huykon commented 6 years ago

Can anyone resolved this problem? I have same it :(( Help meeeeee

kennblvnp commented 6 years ago

have you read all the conversation? there are solutions you can try if you read it. @huykon

ravsourabh commented 6 years ago

@mianshargeel I had the exact problem. I needed mysql driver. So just install php-mysql

huykon commented 6 years ago

@kennblvnp I have read all and changing DB_HOST in your .env to 127.0.0.1 but this is not resolve. Can you help me?

neoacevedo commented 6 years ago

Try using get_cfg_val

kennblvnp commented 6 years ago

Hey @huykon have you already tried this?

DB_HOST=localhost;unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock

ghost commented 6 years ago

I solved the same issue by verifying in /config/database.php the lines 50/51 'charset' => 'utf8', 'collation' => 'utf8_general_ci', Make sure the values correspond to your Database settings.

rotaralek commented 6 years ago

Just dont't use sleeping owl base ".env" file, use laravel ".env". Here is example of correct data: APP_NAME=Laravel APP_ENV=local APP_KEY=base64:Bzu2Qk1vQ2WahfXJeuPSV95dpEGNmmjJ30aB9ZNmdHA= APP_DEBUG=true APP_URL=http://localhost

LOG_CHANNEL=stack

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

BROADCAST_DRIVER=log CACHE_DRIVER=file SESSION_DRIVER=file SESSION_LIFETIME=120 QUEUE_DRIVER=sync

REDIS_HOST=127.0.0.1 REDIS_PASSWORD=null REDIS_PORT=6379

MAIL_DRIVER=smtp MAIL_HOST=smtp.gmail.com MAIL_PORT=587 MAIL_USERNAME=rotaralek@gmail.com MAIL_PASSWORD=newrotar MAIL_ENCRYPTION=tls

PUSHER_APP_ID= PUSHER_APP_KEY= PUSHER_APP_SECRET= PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"

Miguel-Serejo commented 6 years ago

@rotaralek You might want to edit your post and remove your gmail credentials.

alloyking commented 6 years ago

Using 127.0.0.1 worked for me. I was a little surprised as to why, as it worked under localhost until recently. I traced it back to me enabling the Firewall on my Mac.

chrisparma commented 6 years ago

php artisan config:cache solved it for me - nothing else had helped

dwiriyant commented 6 years ago

I had this issue too on fresh Laravel 5.6,

lluminate\Database\QueryException : SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = projectLDM and table_name = migrations)

beidilu commented 6 years ago

Same Problem. SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table
_schema = test and table_name = migrations)

dwiriyant commented 6 years ago

hi @beidilu, i've solved this problem, don't use PHP 7.2.5, after i downgrade PHP version to 7.1.17, the error does not show up. i don't know why

beidilu commented 6 years ago

Thanks, ganyuciha. That's good to know. I just switched to Windows :(

anushanw commented 6 years ago

Using the 127.0.0.1 instead of "localhost" for DB_HOST should fix in most cases. Not sure why this is, but this has been an issue for some time.

Use: DB_HOST=127.0.0.1

megamindAT commented 6 years ago

see below https://stackoverflow.com/questions/42909397/laravel-5-4-on-php-7-0-pdo-exception-could-not-find-driver-mysqlc/42925908

Shrekie commented 6 years ago

In .env in project

DB_PORT=3306 to DB_PORT=33060

also for the PHP requests to work do DB_HOST=localhost

Fixed for me 🤷.

Windows.

ggdal commented 6 years ago

uncomment extension=php_pdo_mysql.dll in php.ini

polinadev commented 6 years ago

This solution worked for me:

mysql -uroot -p ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '';

Source: https://laracasts.com/discuss/channels/laravel/caching-sha2-password-error-when-running-php-artisan-migrate

I am on Mac and my info is: Laravel: 5.6.28 PHP: 7.2.7 mysql: 8.0.11 DB_HOST=localhost DB_PORT=3306

Notes: database created and I didn't uncomment extension=php_pdo_mysql.dll in php.ini

anassbaba commented 6 years ago

For Laravel Framework 5.6.33 , use \Illuminate\Database\Schema\Builder::defaultStringLength(191);