Skip to content

MySQL error – ..but as of v2.0 you must provide streamFactory option returning ReadStream – How to fix?

In this post we will take a look at how to resolve the MySQL error – Error: As a result of LOCAL INFILE command server wants to read emp.csv file, but as of v2.0 you must provide streamFactory option returning ReadStream.

This error occurs when you import a CSV file to a table in MySQL / MariaDB. To read files from the filesystem, since mysql2 we have to explicitly specific the infileStreamFactory when we create a new connection.

const conn = mysql.createConnection({
  //..
  //..
  infileStreamFactory: path => fs.createReadStream(path)
})

The MySQL client that you have been using should also be updated to read files from your local system.

See also  Convert column names to lowercase in Oracle SQL query results

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.