简体   繁体   中英

mysql 5.1.73 load data local infile error

I'm trying to load data into a mysql table using LOAD DATA LOCAL INFILE using the code below.

LOAD DATA LOCAL INFILE 'unziped/product.csv' INTO TABLE producttemp FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\\r\\n'

Until couple days ago this my script was working fine but then hosting company is updated mysql to 5.1.73 and now im geting error "The used command is not allowed with this MySQL version".

I dont know what version was before on server.This command also works fine on mysql 5.3 and 5.5

What can be problem here?

I tried to google but cant find any similar problem

If you run that command from PHP code, the LOAD DATA LOCAL INFILE command can be enabled on the connection to the MySQL server.

The exact procedure depends on the PHP extension used for communication with MySQL.

Using the old, deprecated, mysql extension:

Put 128 into the parameter $flags of mysql_connect() , OR -ed, as usual, with other MYSQL_CLIENT_* flags you may need. The value 128 enables LOAD DATA LOCAL handling but there is no constant defined for it. Read the documentation page for mysql_connect() .

// Put your connection parameters in $server, $username, $password as usual
$server   = '127.0.0.1';
$username = 'root';
$password = '****';
// Put 128 bitwise OR-ed with other flags, if needed
$flags = 128;
// ... and connect
$link = mysql_connect($server, $username, $password, $new_link, $flags);

Using the mysqli extension:

Use the mysqli_options() function to set MYSQLI_OPT_LOCAL_INFILE to TRUE :

$link = mysqli_init();
mysqli_options($link, MYSQLI_OPT_LOCAL_INFILE, TRUE);
mysqli_real_connect($server, $username, $password);

As it is explained in the documentation, this is the correct way to use mysqli_options() .

Using PDO :

Set the option PDO::MYSQL_ATTR_LOCAL_INFILE to TRUE on $options parameter of the PDO constructor:

$options = array(
    PDO::MYSQL_ATTR_LOCAL_INFILE = TRUE;
);
$link = new PDO($dsn, $username, $password, $options);

It's probably because the default settings in /etc/my.conf changed There's a flag that should be set to make that work again:

local-infile = 1

You could als try to connect via commandline and explicitley set the flag:

mysql --local-infile -u root -p db_name

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