1

I recently did a fresh install of mysql 8.0.19 via homebrew on macOS High Sierra 10.13.6. I can see that the mysql service is started when I do brew services list. I can also login via the console with mysql -u root and execute queries and whatnot.

I've installed a fresh Laravel project using Valet but cannot run database migrations. My environment variables all look to be correct:

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

I can connect to MySQL Workbench using this information (no root pw). Yet, whenever I run php artisan migrate I get no errors and no console output whatsoever. It just gets stuck. Same thing happens when I go in with php artisan tinker and then DB::connection()->getPdo(). No output and no errors. Nothing gets logged in storage/logs either.

Relevant config/database.php:

...

'default' => env('DB_CONNECTION', 'mysql'),


'connections' => [


    'mysql' => [
        'driver' => 'mysql',
        'url' => env('DATABASE_URL'),
        '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' => '',
        'prefix_indexes' => true,
        'strict' => true,
        'engine' => null,
        'options' => extension_loaded('pdo_mysql') ? array_filter([
            PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
        ]) : [],
    ],

],

...

Dumping DB::connection() on a random view yields the correct config:

protected 'config' => 
    array (size=15)
      'driver' => string 'mysql' (length=5)
      'host' => string '127.0.0.1' (length=9)
      'port' => string '3306' (length=4)
      'database' => string 'laravel' (length=7)
      'username' => string 'root' (length=4)
      'password' => string '' (length=0)
      'unix_socket' => string '' (length=0)
      'charset' => string 'utf8mb4' (length=7)
      'collation' => string 'utf8mb4_unicode_ci' (length=18)
      'prefix' => string '' (length=0)
      'prefix_indexes' => boolean true
      'strict' => boolean true
      'engine' => null
      'options' => 
        array (size=0)
          empty
      'name' => string 'mysql' (length=5)
10
  • did you try other artisan commands? Commented Jan 19, 2020 at 17:40
  • Yes something like php artisan make:policy Foobar works as expected. I can also load views in the browser just fine, just no DB interaction. Commented Jan 19, 2020 at 17:42
  • are you sure your env file overwrites your config file? Commented Jan 19, 2020 at 17:44
  • Looks like it, php artisan tinker and env('DB_DATABASE', 'foobar') shows the correct info from the .env file. The config/database.php file also looks correct. Commented Jan 19, 2020 at 17:47
  • to be sure try to copy the same infos from env file to config\database.php file Commented Jan 19, 2020 at 17:50

1 Answer 1

0

I attempted running a simple new mysqli(...) on a plain PHP script and it failed as well, so it wasn't a Laravel thing.

After doing some more research on this, the solution was just to downgrade my PHP/MySQL versions. I was using PHP 7.4+ and MySQL 8+. I've now rolled back to PHP ~7.3 and MySQL ~5.7.

I came across this recent thread which detailed the problem. Something having to do with a new default MySQL authentication plugin. I attempted manually changing it in the database as detailed in that thread as well as here but didn't have any luck.

Rolling back was easiest for me, thanks everyone!

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.