vendredi 26 janvier 2018

MySQL denies access only to laravel

For some reason, MySQL won't connect for one specific webapp. It will connect from the CLI, Sequel Pro (like Mysql Workbench), even a webapp hosted in a sibling directory (~/projects/iwork/, ~/projects/idontwork).

The only difference I can see is that the broken one is a laravel instance.

My .env:

DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=idontwork_db
DB_USERNAME=dev
DB_PASSWORD=password

The error:

SQLSTATE[HY000] [1045] Access denied for user 'dev'@'localhost' (using password: YES) (SQL: select * from `instances` limit 1)

My config/database.php (this is unchanged from laravel's default):

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

The dump of config('database.connections.mysql') as requested:

array:11 [▼
  "driver" => "mysql"
  "host" => "localhost"
  "port" => "3306"
  "database" => "idontwork_db"
  "username" => "dev"
  "password" => "nottherightpassword"
  "charset" => "utf8"
  "collation" => "utf8_unicode_ci"
  "prefix" => ""
  "strict" => false
  "engine" => null
]

The sibling webapp that works:

$DB_HOST = 'localhost';
$DB_NAME = 'iwork_db';
$DB_USER = 'dev';
$DB_PASS = 'password';

$dbc = new PDO('mysql:host=' . $DB_HOST . ';dbname=' . $DB_NAME, $DB_USER, $DB_PASS);
$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

So obviously one is trying to connect via Laravel and the other is native PDO, but I can't see any reason this should make a difference.

Things I've done:

  • Composer and NPM have both installed their packages.
  • I tried 127.0.0.1 and localhost.
  • I've ensured the credentials are valid (like I said, I can get to idontwork_db from the CLI and Sequel Pro)
  • Everything I've found on google seems to think I'm running out of connections, but this does not appear to be the case.

At this point I legitimately have no idea what is broken or how to troubleshoot it. Any assistance would be appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire