0

Trying to load CSV data to remote MySQL Server using following command in MySQL Server 5.5, and using PHP-5.6 PDO connection.

LOAD DATA INFILE :file INTO TABLE test_csv COLUMNS 
TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\n';

But i'm getting the following error:

PHP Warning: chown(): Unable to find uid for mysql in /var/www/proj/csvtodb.php on line 22 2017-12-26 09:21:18,

SQLSTATE[HY000]: General error: 13 Can't get stat of '/tmp/csvfile-1.csv' (Errcode: 2)

Please help us to fix this issue.

sk2
  • 1,171
  • 1
  • 10
  • 28
  • Is the file located on the remote server or on the client server? If it's on the client server, you need to use `LOAD DATA LOCAL INFILE`. – Barmar Dec 26 '17 at 09:32
  • The first warning has nothing to do with the MySQL query, it's from a call to `chown()` earlier in the script. – Barmar Dec 26 '17 at 09:34
  • @barmar: csv file is in client server only – sk2 Dec 26 '17 at 09:39

1 Answers1

0

If the CSV file is located on the PHP server running the script, not the remote MySQL server, you need to use LOAD DATA LOCAL INFILE. LOAD DATA INFILE looks for the file on the MySQL server.

Barmar
  • 741,623
  • 53
  • 500
  • 612
  • i changed as you said, still i'm getting following error PHP Warning: chown(): Unable to find uid for mysql in /var/www/proj/csvtodb.php on line 22 PHP Warning: PDOStatement::execute(): LOAD DATA LOCAL INFILE forbidden in /var/www/proj/comm.php on line 445 – sk2 Dec 26 '17 at 09:42
  • See https://stackoverflow.com/questions/7638090/load-data-local-infile-forbidden-in-php – Barmar Dec 26 '17 at 09:48
  • The `chown()` error is because there's no username `mysql` in `/etc/passwd`, and you're trying to do something like `chown($filename, "mysql");` – Barmar Dec 26 '17 at 09:51
  • i tried with this solutions https://stackoverflow.com/questions/7638090/load-data-local-infile-forbidden-in-php but still getting same error – sk2 Dec 26 '17 at 11:00
  • Since it's a MySQL configuration problem of some kind, try asking in dba.stackexchange.com. – Barmar Dec 26 '17 at 17:15