How to Solve Error Message file not found (Errcode: 22 – Invalid argument) upon load CSV file into a MySQL Table

Posted on

Introduction

This article is on how to solve an error message appear upon loading a CSV file into a MySQL table. Actually, there is a file with a CSV file extension. The file is a comma separated version with the separation character between one value with another in one row is a comma. So, after generating the file, the is a further processing step ahead. That processing step is by loading each row of the record exist in the CSV file into a MySQL table. For more information, the CSV file has a row header with each column has an associated column with the MySQL table’s destination.

In this context, there is a table with the name of tbl_data. The table exist in a MySQL database server. The MySQL database server has the version of ‘5.6.20’. The following is the first step upon executing the command for loading the CSV file into a table exist in MySQL database server :

C:\Users\Personal>mysql -uroot -hlocalhost db_temp
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.20 MySQL Community Server (GPL)

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

The following after, executing the command for loading CSV file into a table exist MySQL database server as follows :

load data infile 'C:\temp\file_csv.csv' into table tbl_data fields terminated by ',';
ERROR 29 (HY000): File 'C:\uWamp\bin\database\mysql-5.6.20\data\      empcsv_file.csv' not found (Errcode: 22 - Invalid argument)
mysql>

Solution

Apparently, it is generating an error as in the output above. The solution is actually simple. It is because the backslash character does not representing a separator for path inside the single quote. So, the command does not understand the path at all. In order for the command to recognize the backslash character as a separator for path, just add another backslash character. So, the command will be in the following execution :

mysql> load data infile 'C:\\temp\\file_csv.csv' into table tbl_data fields terminated by ',';
Query OK, 311 rows affected, 4402 warnings (0.36 sec)
Records: 311  Deleted: 0  Skipped: 0  Warnings: 4402

mysql>

As in the above output command execution, it is finally a success. It is a success by modifying the path separator and make it as a double backslash. So the first backslash character will act as an escape character providing the next backslash as the backslash to act as a separator for path.

Leave a Reply