Reputation: 1
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
Upvotes: 0
Views: 1393
Reputation: 72376
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.
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);
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()
.
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);
Upvotes: 1
Reputation: 26
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
Upvotes: 0