Support the ongoing development of Laravel.io →
Database
Last updated 2 years ago.
0

I was just banging my head against the wall last night with this issue --

What I did was to write the import file to the system's temp folder (machine's, not something in storage_path() -- i used sys_get_temp_dir() -- may not be doable or safe on shared hosting.), run the import, then delete the file directly afterwards. That way MySQL doesn't have a permission issue.

The second step to getting around the permissions issue was to use LOAD DATA LOCAL INFILE ...

This all worked wonderfully on my dev machine, but on the server, i got the error that LOAD DATA LOCCAL INFILE forbidden. AGHHHH -- so this took me a while to figure out but finally what it came down to was that I needed to set an option in the PDO class in order to enable it. BUT, the option was required to be set at instantiation, and Laravel was already bootstrapping PDO on it's own.

The solution was so simple, yet not in the official documentation -- I needed to add an options key to my database connection array, like so:

'mysql' => [
    ...
    'options' => [
        PDO::MYSQL_ATTR_LOCAL_INFILE => true
    ],
],

And then it worked like a charm!

Last updated 10 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.