简体   繁体   中英

Malformed packet error during MySQL LOAD DATA LOCAL INFILE

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM