Error when Migrating, can't connect to database?

Published 3 months ago by Gabotronix

Hello I am new to laravel and tried to do my first migration today. I created a costadog database with phpmyadmin, then I changed both config/database and .env file default credentials to this:

'mysql' => [
            'driver' => 'mysql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'costadog'),
            'username' => env('DB_USERNAME', 'root'),
            'password' => env('DB_PASSWORD', 'root'),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8',                              //antes era: utf8mb4
            'collation' => 'utf8mb4_unicode_ci',              //antes era: utf8mb4_unicode_ci
            'prefix' => '',
            'strict' => true,
            'engine' => null,
        ],

and...

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

after executing php artisan migrate I got the following errors:

   Illuminate\Database\QueryException  : SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = costadog and table_name = migrations)

  at C:\xampp\htdocs\Costadog\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] [1045] Access denied for user 'root'@'localhost' (using password: YES)")
      C:\xampp\htdocs\Costadog\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:68

  2   PDO::__construct("mysql:host=127.0.0.1;port=3306;dbname=costadog", "root", "root", [])
      C:\xampp\htdocs\Costadog\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:68

  Please use the argument -v to see more details.

rin4ik
rin4ik
3 months ago (200,250 XP)

these credentials are correct? maybe u have another password?

DB_USERNAME=root
DB_PASSWORD=root

try

php artisan config:clear
Gabotronix

Yes these credentials are the same in both files, maybe they are different to my phpmyadmin user and password? it keeps refusing my connection, DB_HOST and DB_PORT are also correctly set:

´´´ 'mysql' => [ 'driver' => 'mysql', 'host' => env('DB_HOST', '127.0.0.1'), 'port' => env('DB_PORT', '3306'), 'database' => env('DB_DATABASE', 'costadog'), 'username' => env('DB_USERNAME', 'root'), 'password' => env('DB_PASSWORD', 'root'), 'unix_socket' => env('DB_SOCKET', ''), 'charset' => 'utf8', //antes era: utf8mb4 'collation' => 'utf8mb4_unicode_ci', //antes era: utf8mb4_unicode_ci 'prefix' => '', 'strict' => true, 'engine' => null, ], ´´´ ´´´ DB_CONNECTION=mysql DB_HOST=127.0.0.1 DB_PORT=3306 DB_DATABASE=costadog DB_USERNAME=root DB_PASSWORD=root ´´´

rin4ik
rin4ik
3 months ago (200,250 XP)

yes I think so . go to phpmyadmin and check

Gabotronix

where can I change my phpmyadmin credentials?

rin4ik
rin4ik
3 months ago (200,250 XP)
Gabotronix

I fixed it changing my credentials in the php.inc.config file, thanks for the help everybody!

Please sign in or create an account to participate in this conversation.