tags:

views:

16

answers:

2

while I am adding details in database through CSV file I am getting error- Access denied for user 'user'@'%' (using password: YES) . I have checked database username and password. even if I add product one by one(without csv) it is workin fine. It means my database connectivity is correct. Do I need to make some change in my database hosting accoun or some code error?

connect_db(); // MYSQL connection settings


    $sql="LOAD DATA 
    INFILE '$file_name' INTO TABLE tbl_product 
    IELDS TERMINATED BY \"\t\" 
    LINES TERMINATED BY \"\n\" 
    ( cat_id, pd_name, pd_description, pd_price, pd_qty, pd_image, pd_thumbnail, pd_date, pd_last_update, tax)";
+1  A: 

Looks like your MySQL user doesn't have the correct permissions

Try executing this and then flush

grant file on *.* to user@host identified by 'password';

Adding ref link

Phill Pafford
+1  A: 

You might not have FILE permissions required in order to load a file. Documentation for the LOAD DATA INFILE statement states:

For security reasons, when reading text files located on the server, the files must either reside in the database directory or be readable by all. Also, to use LOAD DATA INFILE on server files, you must have the FILE privilege. See Section 5.4.1, “Privileges Provided by MySQL”. For non-LOCAL load operations, if the secure_file_priv system variable is set to a nonempty directory name, the file to be loaded must be located in that directory.

thetaiko