title: Laravel - SQLSTATE[HY000] [1049] Unknown database
body: <p><strong>Solved: Check your ports people!</strong></p>
  <p>.</p>
  <p><strong>Tools:</strong></p>
  <p>I am using Windows 10, Wamp 3.2, and Laravel. I have a Laravel 6.5.1 project which I backed up by zipping its www project file and I also downloaded the database in an &quot;.sql&quot; file using phpMyAdmin. I recently made a clean installation of Windows 10, and installed Wamp 3.2, composer and of course, Laravel. I have also installed php 7.4.1 separately, and I am currently using that in my PATH (instead of Wamp's php 7.4.0).</p>
  <p><strong>Goal:</strong></p>
  <p>What I simply want to do now, is to restore my project so I can continue its development.
  I unzipped the project files into the www directory, and uploaded the database back into phpMyAdmin, with the exact name and collation as before.
  I also edited the PHP7 &quot;php.ini&quot; file, in order to allow the necessary extensions to run (for this step I copied the enabled extensions from wamp's php 7.4.0 coherent file).</p>
  <p><strong>Problem:</strong></p>
  <p>At this point I would expect everything to run normally, but not exactly. The project does seem to run fine when the requested page does not involve the database (other projects that do not involve the database also work fine).
  When the database is involved, this error is thrown: &quot;Illuminate\Database\QueryException
  SQLSTATE[HY000] [1049] Unknown database 'sportlog' (relevant database query is placed right after)&quot;.</p>
  <p><strong>Tried:</strong></p>
  <p>I tried some commands asked in <a href="https://stackoverflow.com/questions/24119818/laravel-pdoexception-sqlstatehy000-1049-unknown-database-forge">this similar question</a>, like <code>php artisan cache:clear</code> and <code>php artisan migrate:install</code> but none of these brought a different result. I changed the value of the <code>DB_DATABASE</code> variable of the <strong>.env</strong> file from &quot;<em>sportlog</em>&quot; to &quot;<em>space</em>&quot;, which is the name of another existing database, yet the same error occured, updated to &quot;<em>space</em>&quot; this time.</p>
  <p>Can anyone help me solve this ?</p>
  <p><strong>database.php</strong> file</p>
  <pre><code>/*
      |--------------------------------------------------------------------------
      | Default Database Connection Name
      |--------------------------------------------------------------------------
      |
      | Here you may specify which of the database connections below you wish
      | to use as your default connection for all database work. Of course
      | you may use many connections at once using the Database library.
      |
      */
  
      'default' =&gt; env('DB_CONNECTION', 'mysql'),
  
      /*
      |--------------------------------------------------------------------------
      | Database Connections
      |--------------------------------------------------------------------------
      |
      | Here are each of the database connections setup for your application.
      | Of course, examples of configuring each database platform that is
      | supported by Laravel is shown below to make development simple.
      |
      |
      | All database work in Laravel is done through the PHP PDO facilities
      | so make sure you have the driver for your particular database of
      | choice installed on your machine before you begin development.
      |
      */
      'connections' =&gt; [
      
              'sqlite' =&gt; [
                  'driver' =&gt; 'sqlite',
                  'url' =&gt; env('DATABASE_URL'),
                  'database' =&gt; env('DB_DATABASE', database_path('database.sqlite')),
                  'prefix' =&gt; '',
                  'foreign_key_constraints' =&gt; env('DB_FOREIGN_KEYS', true),
              ],
      
              'mysql' =&gt; [
                  'driver' =&gt; 'mysql',
                  'url' =&gt; env('DATABASE_URL'),
                  'host' =&gt; env('DB_HOST', '127.0.0.1'),
                  'port' =&gt; env('DB_PORT', '3306'),
                  'database' =&gt; env('DB_DATABASE', 'forge'),
                  'username' =&gt; env('DB_USERNAME', 'forge'),
                  'password' =&gt; env('DB_PASSWORD', ''),
                  'unix_socket' =&gt; env('DB_SOCKET', ''),
                  'charset' =&gt; 'utf8mb4',
                  'collation' =&gt; 'utf8mb4_unicode_ci',
                  'prefix' =&gt; '',
                  'prefix_indexes' =&gt; true,
                  'strict' =&gt; true,
                  'engine' =&gt; 'InnoDB', //default value was null, InnoDB is supposed to allow key constraints aka database foreign keys to work properly
                  'options' =&gt; extension_loaded('pdo_mysql') ? array_filter([
                      PDO::MYSQL_ATTR_SSL_CA =&gt; env('MYSQL_ATTR_SSL_CA'),
                  ]) : [],
              ],
      
              'pgsql' =&gt; [
                  'driver' =&gt; 'pgsql',
                  'url' =&gt; env('DATABASE_URL'),
                  'host' =&gt; env('DB_HOST', '127.0.0.1'),
                  'port' =&gt; env('DB_PORT', '5432'),
                  'database' =&gt; env('DB_DATABASE', 'forge'),
                  'username' =&gt; env('DB_USERNAME', 'forge'),
                  'password' =&gt; env('DB_PASSWORD', ''),
                  'charset' =&gt; 'utf8',
                  'prefix' =&gt; '',
                  'prefix_indexes' =&gt; true,
                  'schema' =&gt; 'public',
                  'sslmode' =&gt; 'prefer',
              ],
      
              'sqlsrv' =&gt; [
                  'driver' =&gt; 'sqlsrv',
                  'url' =&gt; env('DATABASE_URL'),
                  'host' =&gt; env('DB_HOST', 'localhost'),
                  'port' =&gt; env('DB_PORT', '1433'),
                  'database' =&gt; env('DB_DATABASE', 'forge'),
                  'username' =&gt; env('DB_USERNAME', 'forge'),
                  'password' =&gt; env('DB_PASSWORD', ''),
                  'charset' =&gt; 'utf8',
                  'prefix' =&gt; '',
                  'prefix_indexes' =&gt; true,
              ],
      
          ],
      
          /*
          |--------------------------------------------------------------------------
          | Migration Repository Table
          |--------------------------------------------------------------------------
          |
          | This table keeps track of all the migrations that have already run for
          | your application. Using this information, we can determine which of
          | the migrations on disk haven't actually been run in the database.
          |
          */
      
          'migrations' =&gt; 'migrations',
      
          /*
          |--------------------------------------------------------------------------
          | Redis Databases
          |--------------------------------------------------------------------------
          |
          | Redis is an open source, fast, and advanced key-value store that also
          | provides a richer body of commands than a typical key-value system
          | such as APC or Memcached. Laravel makes it easy to dig right in.
          |
          */
      
          'redis' =&gt; [
      
              'client' =&gt; env('REDIS_CLIENT', 'phpredis'),
      
              'options' =&gt; [
                  'cluster' =&gt; env('REDIS_CLUSTER', 'redis'),
                  'prefix' =&gt; env('REDIS_PREFIX', Str::slug(env('APP_NAME', 'laravel'), '_').'_database_'),
              ],
      
              'default' =&gt; [
                  'url' =&gt; env('REDIS_URL'),
                  'host' =&gt; env('REDIS_HOST', '127.0.0.1'),
                  'password' =&gt; env('REDIS_PASSWORD', null),
                  'port' =&gt; env('REDIS_PORT', 6379),
                  'database' =&gt; env('REDIS_DB', 0),
              ],
      
              'cache' =&gt; [
                  'url' =&gt; env('REDIS_URL'),
                  'host' =&gt; env('REDIS_HOST', '127.0.0.1'),
                  'password' =&gt; env('REDIS_PASSWORD', null),
                  'port' =&gt; env('REDIS_PORT', 6379),
                  'database' =&gt; env('REDIS_CACHE_DB', 1),
              ],
      
          ],
  </code></pre>
  <p><strong>.env</strong> file</p>
  <pre><code>APP_NAME=Laravel
  APP_ENV=local
  APP_KEY=base64:somekey
  APP_DEBUG=true
  APP_URL=http://localhost
  
  LOG_CHANNEL=stack
  
  DB_CONNECTION=mysql
  DB_HOST=127.0.0.1
  DB_PORT=3306
  DB_DATABASE=sportlog
  DB_USERNAME=root
  DB_PASSWORD=
  
  BROADCAST_DRIVER=log
  CACHE_DRIVER=file
  QUEUE_CONNECTION=sync
  SESSION_DRIVER=file
  SESSION_LIFETIME=120
  
  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
  
  AWS_ACCESS_KEY_ID=
  AWS_SECRET_ACCESS_KEY=
  AWS_DEFAULT_REGION=us-east-1
  AWS_BUCKET=
  
  PUSHER_APP_ID=
  PUSHER_APP_KEY=
  PUSHER_APP_SECRET=
  PUSHER_APP_CLUSTER=mt1
  
  MIX_PUSHER_APP_KEY=&quot;${PUSHER_APP_KEY}&quot;
  MIX_PUSHER_APP_CLUSTER=&quot;${PUSHER_APP_CLUSTER}&quot;
  </code></pre>
  <p><strong>php.ini</strong> extensions</p>
  <pre><code>extension=bz2
  extension=curl
  ;extension=dba
  ;extension=com_dotnet
  ;extension=enchant
  ;extension=ffi
  extension=fileinfo
  ;extension=ftp
  extension=gd2
  extension=gettext
  extension=gmp
  extension=intl
  extension=imap
  extension=ldap
  extension=mbstring
  extension=exif      ; Must be after mbstring as it depends on it
  extension=mysqli
  ;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
  ;extension=odbc
  extension=openssl
  ;extension=pdo_firebird
  extension=pdo_mysql
  ;extension=pdo_oci
  ;extension=pdo_odbc
  ;extension=pdo_pgsql
  extension=pdo_sqlite
  ;extension=pgsql
  ;extension=phpdbg_webhelper
  ;extension=shmop
  
  ; The MIBS data available in the PHP distribution must be installed.
  ; See http://www.php.net/manual/en/snmp.installation.php
  ;extension=snmp
  
  extension=soap
  extension=sockets
  ;extension=sodium
  ;extension=sqlite3
  ;extension=sysvshm
  ;extension=tidy
  extension=xmlrpc
  extension=xsl
  ;extension=zend_test
  </code></pre>