1

I am trying to load a file into an MySQL(v5.1.38) innodb table using PHP's mysqli::query and a LOAD DATA LOCAL INFILE query. The query returns a 'Malformed packet' error code 2027. Any ideas what is wrong?

Here is the target table:

CREATE TABLE  `zbroom`.`lee_datareceive` (
  `a` varchar(45) NOT NULL,
  `b` varchar(45) NOT NULL,
  `c` varchar(45) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Here is the query:

LOAD DATA LOCAL INFILE '/path/to/file.txt'
    INTO TABLE lee_datareceive
    FIELDS TERMINATED BY '\t';

Here is the file data. Values are tab separated:

t1  t2  t3
a   b   c
d   e   f
g   h   i
dnagirl
  • 20,196
  • 13
  • 80
  • 123

1 Answers1

0

same problem. it was permission problem.

shell exec from php:

'mysql --user=root --password=zxc db < /stuff.sql'

stuff.sql

LOAD DATA LOCAL INFILE '/stuff.csv' INTO TABLE `stuff` FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'

Errors with malformed packets.

Solution:

chmod 777 /stuff.csv

PHP is running on its own permission level and mysql isn't getting read access to stuff.csv

You get a cookie if you hate chmod 777

rekire
  • 47,260
  • 30
  • 167
  • 264
Rob Lowe
  • 9
  • 1
  • 1
    644 would be adequate :) 777 means the user, group and the whole world can read, write to and execute the file. You almost never, ever want that. – Tim Post May 30 '10 at 19:18
  • In my case changing permissions was not adequate. I ended up calling a local Perl script from PHP. Of course, then I had difficulties with piping the results, but that is a different story! – dnagirl May 31 '10 at 12:28