Skip to content

Instantly share code, notes, and snippets.

@NBZ4live
Last active June 13, 2018 12:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NBZ4live/e48d24c948a2be93ae5c9fc5eeaaf779 to your computer and use it in GitHub Desktop.
Save NBZ4live/e48d24c948a2be93ae5c9fc5eeaaf779 to your computer and use it in GitHub Desktop.
Print MySQL Grants for all not working connections configured in Laravel
<?php
$userHost = '%';
foreach(config('database.connections') as $name => $connection) {
if ($connection['driver'] != 'mysql') {
continue;
}
try {
\DB::connection($name)->getPdo();
} catch(\Doctrine\DBAL\Driver\PDOException $exception) {
$host = $connection['host'] ?? $connection['write']['host'];
print "{$name}({$host}) --- GRANT ALL ON {$connection['database']}.* TO '{$connection['username']}'@'{$userHost}' IDENTIFIED BY \"{$connection['password']}\";\n";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment