Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Kenzic's avatar

SQLSTATE[HY000] [2002] No such file or directory

I have created a schedule wich should import a xml file into the database. But when i run this schedule i get a "SQLSTATE[HY000] [2002] No such file or directory" error.

But when i run the same script manualy from the site it works perfectly


   Illuminate\Database\QueryException

  SQLSTATE[HY000] [2002] No such file or directory (SQL: select `company` from `company`)

  at vendorframework/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|

      +19 vendor frames
  20  app/Console/Commands/importXML.php:47
      Illuminate\Database\Eloquent\Builder::get()

      +14 vendor frames
  35  artisan:37
      Illuminate\Foundation\Console\Kernel::handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symf
bash-4.2$  /opt/plesk/php/7.3/bin/php artisan import:XMLmutaties


0 likes
9 replies
automica's avatar

@kenzic sounds like it relates to permissions. is the user running the schedule (cron) the same as your www user?

Kenzic's avatar

Thanks for replying, i did not set any users for the schedule. I assumed it would use the same creditentials wich are in the env file.

Where can you set these permissions?

automica's avatar

@kenzic so running this '/opt/plesk/php/7.3/bin/php artisan import:XMLmutaties' causes error?

how would you run it manually and how do you know its worked correct?

have you checked that you have the file and its in the correct location?

Kenzic's avatar

Yes when i run '/opt/plesk/php/7.3/bin/php artisan import:XMLmutaties' i get the error.

On the website there is a button that runs the script and that works 100%. The script checks if there are files in the storage/app directory there are 18 in it now so thats not the problem.

If i run this code instead i get the same error

$test = DB::table('company')
  	->select('cashwin_number')
        ->get();
automica's avatar

@kenzic i'd expect tables to be plural if you are following Laravel conventions.

can you post the migration for your company table?

Kenzic's avatar
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCompanyTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('company', function (Blueprint $table) {
            $table->bigIncrements('company_id');
            $table->string('company_name', 100);
            $table->string('company_address_line1', 100);
            $table->string('company_address_line2', 100);
            $table->string('company_city', 50);
            $table->string('company_postal_code', 7);
            $table->string('company_country', 30);
            $table->string('company_email', 100);
            $table->string('company_phone', 10);
            $table->integer('cashwin_number', 4)->unique();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('company');
    }
}

Tried it with a different table but it also has the same error.

uttamrabadiya's avatar

Looks like your MySQL connection is not working properly.

Try the same query select * from company in MySQL cli directly, and see if that works.

If it is, then try installing php7.3-mysql and it should fix your trouble

Kenzic's avatar

On my local machine its working with out any problems. Only at the website host its not working but it does work when you run it manually but not if its within a schedule. Really confusion :p

I found a possible solutions wich says you should change the DB_HOST from localhost to 127.0.0.1 but then i get a access denied.

So wrote a email to my host hoping they can change this.

Waiting for a reply now.

Thanks for helping

Kenzic's avatar
Kenzic
OP
Best Answer
Level 1

Changing the DB_HOST=localhost to DB_HOST=127.0.0.1 in the .env file did the trick.

Please or to participate in this conversation.