laravel / framework

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

[5.6] QueryException Error with Mysql 8.0.12 #25173

Closed Michi441 closed 6 years ago

Michi441 commented 6 years ago

Description:

After reading & trying all kinds of different solutions, i can't connect my application to my database via 'php artisan migrate'. No matter what i do, i always get the error:

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)

My .env file:

APP_NAME=Laravel
APP_ENV=local
APP_KEY=base64:pQHW+AbJH5EhLErwLmqVQu13YMXX0N7JuNPQUBkLKkQ=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=blog
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.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

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}"

Saw that i need to change inside database.php the mysql configuration, which i did:

        '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,
            'modes' => [
             'ONLY_FULL_GROUP_BY',
             'STRICT_TRANS_TABLES',
             'NO_ZERO_IN_DATE',
             'NO_ZERO_DATE',
             'ERROR_FOR_DIVISION_BY_ZERO',
             'NO_ENGINE_SUBSTITUTION',
         ],
        ],

Some suggested to use in .env the ip adress 127.0.0.1 instead of localhost, still same result.

Sequel Pro was also unable to connect, but then i read that i have to add all privileges to the current user (root), which i did. Since then, i can connect via Sequel Pro to Mysql, however, Laravel always gives back the error shown before.

Here's the full error log when running php artisan migrate:

  Illuminate\Database\QueryException  : SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from information_schema.tables where table_schema = blog and table_name = migrations)

  at /Users/UserMac/Desktop/laravel_blog/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664
    660|         // If an exception occurs when attempting to run a query, we'll format the error
    661|         // message to include the bindings with SQL, which will make this exception a
    662|         // lot more helpful to the developer instead of just the database's errors.
    663|         catch (Exception $e) {
  > 664|             throw new QueryException(
    665|                 $query, $this->prepareBindings($bindings), $e
    666|             );
    667|         }
    668| 

  Exception trace:

  1   PDOException::("SQLSTATE[HY000] [2002] No such file or directory")
      /Users/UserMac/Desktop/laravel_blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

  2   PDO::__construct("mysql:host=localhost;port=3306;dbname=blog", "root", "", [])
      /Users/UserMac/Desktop/laravel_blog/vendor/laravel/framework/src/Illuminate/Database/Connectors/Connector.php:68

Please use the argument -v to see more details.

Steps To Reproduce:

laravel new 'name'

brew services start mysql

mysql -uroot

mysql use blog;

change .env file with database name, username, password

php artisan migrate

jmarcher commented 6 years ago

Ask this kind of questions in a forum like Laracasts.

siddharthghedia commented 5 years ago

@Prometheus88 did you find any solution?

Michi441 commented 5 years ago

@siddharthghedia Yes. I simply installed mysql@5.7 with homebrew. I also removed all other mysql versions on my mac. Make sure, if you are using homebrew, that only mysql@5.7 is running. You can see all your services via brew services list. I think disabling other mysql versions will be fine, but i went for a clean setup and deleted all versions before installing a fresh installation with 5.7

siddharthghedia commented 5 years ago

@Prometheus88 I'm still receiving this error: SQLSTATE[HY000] [2006] MySQL server has gone away would you mind helping me with this?

Michi441 commented 5 years ago

@siddharthghedia, i would love to, but i have honestly not too much knowledge about MySQL. I found this https://stackoverflow.com/questions/35036547/mysql-server-has-gone-away-error-during-installing-migration-laravel on stackoverflow. Maybe this will/can help? Otherwise try to ask on stackoverflow might be the best bet!

Hope you can fix it asap! Greetings!