简体   繁体   中英

Connection refused SQL: select * from information_schema.tables where table_schema = firstdb and table_name = migrations and table_type = 'BASE TABLE

I have XAMPP installed and turned on which is how I access my phpmyadmin page. I have created a database in phpmyadmin called "firstdb".

I have also created auth in laravel files stored locally. I am trying to migrate tables using php artisan migrate and I am getting the error below.

user@Andress-MacBook-Pro admin-panel % php artisan migrate

   Illuminate\Database\QueryException 

  SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_schema.tables where table_schema = firstdb and table_name = migrations and table_type = 'BASE TABLE')

  at vendor/laravel/framework/src/Illuminate/Database/Connection.php:671
    667|         // If an exception occurs when attempting to run a query, we'll format the error
    668|         // message to include the bindings with SQL, which will make this exception a
    669|         // lot more helpful to the developer instead of just the database's errors.
    670|         catch (Exception $e) {
  > 671|             throw new QueryException(
    672|                 $query, $this->prepareBindings($bindings), $e
    673|             );
    674|         }
    675| 

      +37 vendor frames 
  38  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))

I have looked everywhere, please help.

It could be the wrong mysql port number in your .env file. Check your .env file and make sure the port number matches the same one mysql is using.

I noticed something weird regarding the password that was in the command line output vs what was actually in the env file. Turned out I had a number sign in my password and it was getting cut off.

So check the output after you run php artisan migrate and make sure that the password actually matches the password in your env (and all information for that matter). The fix is to just add quotes if there is a mismatch.

DB_PASSWORD=abcdefghijklmonp5#Q

would become

DB_PASSWORD='abcdefghijklmonp5#Q'

Laravel makes such queries, when you use DB/QueryBuilder. When you use Model and fill there fillable attributes array then code

$model::create(['id' => 1]);

Will just insert in the table of $model. If you dont fill fillable(guard) array Db QueryBuilder will check that such columns exists in this table by performing

    "select column_name as `column_name` from information_schema.columns where table_schema = ? and table_name = ?"

And only then performs insert. Suggestions - to use $model->save() instead of $model::create, or fill fillable attributes for model

In addition to making sure all of your configs are correct escaping password with quotes I ran into a similar issue for a clean install on linux.

SQLSTATE[HY000] [1045] Access denied for user 'username'@'localhost' (using password: YES) (SQL: select * from information_schema.tables where table_schema = studentaffairs and table_name = migrations and table_type = 'BASE TABLE')

To solve the issue I made sure to run composer update and for good measure I ran npm run dev

Then it was able to migrate without issue.

Try to set your DB_HOST on your.env to

DB_HOST=localhost

Try to set on php.ini and search:

;extension=pdo_mysql.so

Delete ";" to uncomment

enter image description here

First, check the the user plugin:

mysql> SELECT User,Host,plugin FROM mysql.user WHERE user='root';

If the user is using caching_sha2_password change to mysql_native_password , because PHP doesn't yet understand caching_sha2_password

mysql>ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password'

In order to set your database host, you need to edit the.env file and specify the desired hostname instead of IP address. To do this, locate the DB_HOST variable in the .env file and assign it the value of "localhost". This will instruct your application to connect to a local database server, which is typically running on the same machine as the application itself.

For example, you might see a line like this in your.env file:

DB_HOST=

To set the hostname to "localhost", you would simply update the line to read:

DB_HOST=localhost

Once you have saved your changes to the.env file, your application should be able to connect to the local database server using the hostname or IP address that you specified.

change DB_CONNECTION=127.0.0.7 TO mysql in .env file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM