问题描述
我正在尝试使用PHP的 mysqli :: query 和 LOAD DATA LOCAL INFILE 查询.该查询返回格式错误的数据包"错误代码2027.有什么想法吗?
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?
这是目标表:
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;
这是查询:
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.
来自php的shell exec:
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.
解决方案:
chmod 777 /stuff.csv
PHP正在其自己的权限级别上运行,并且mysql无法获得对stuff.csv的读取访问权限
PHP is running on its own permission level and mysql isn't getting read access to stuff.csv
如果您讨厌chmod 777
这篇关于MySQL LOAD DATA LOCAL INFILE期间的格式错误的数据包错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!