OS: Ubuntu 12.04.1 LTS
MySQL Version: 5.5.28-0ubuntu0.12.04.2
When I try to run a LOAD DATA LOCAL INFILE I am getting error 1148 (The used command is not allowed with this MySQL version) - but only under the following circumstances
When the command is run via a PHP wget cron job (fails most times, works around every 1 in 4 times)
When the command is run via a PHP file in a browser session (fails twice, then usually works on the third time)
I'm seeing that if the script runs OK, and an effort is made to run it very soon after, it works fine - but waiting 5+ minutes after running it, it begins failing again, until I refresh it enough times to get it to run again. I need to run it successfully every time from cron.
I have added local-infile (not local-infile=1) under the [mysqld], [mysql] and [client] entries in my.conf, then restarted the server, to no avail. I have also tried entering loose-local-infile=1 under [client], but no joy.
The database folder was moved to a different location (/media/Data/mysql_data) and is owned by root.
The import file is downloaded to the local box with the permissions 0644.
Here is the command that's being run:
LOAD DATA LOCAL INFILE
"/var/www/'.$import_dir.$table.'.csv"
INTO TABLE _PREP_'.$table.'
FIELDS TERMINATED BY ","
OPTIONALLY ENCLOSED BY "\""
..$import_dir and $table being the path and name of the import file.
Has anyone else seen this before?
Are there any logs I can view to see why it's failing?
How come it's only intermittently failing?
It's all a bit weird. For the record, this is a new box, and the script has always behaved like this.
All help appreciated.
-PaulG
Adding additional flag 128 to mysql_connect solves the problem for me.
Check this for details mysql_connect
Related
I'm kinda new to SQL. I am trying to add data to an alredy created table, the csv looks like these, it is 132645 lines long:
iso_code;continent;location;date;population;total_cases;new_cases;new_cases_smoothed;total_deaths;new_deaths;new_deaths_smoothed;total_cases_per_million;new_cases_per_million;new_cases_smoothed_per_million;total_deaths_per_million;new_deaths_per_million;new_deaths_smoothed_per_million;reproduction_rate;icu_patients;icu_patients_per_million;hosp_patients;hosp_patients_per_million;weekly_icu_admissions;weekly_icu_admissions_per_million;weekly_hosp_admissions;weekly_hosp_admissions_per_million
AFG;Asia;Afghanistan;24/02/2020;398354280;50;50;NULL;NULL;NULL;NULL;126;126;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;
AFG;Asia;Afghanistan;25/02/2020;398354280;50;0;NULL;NULL;NULL;NULL;126;0;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;
AFG;Asia;Afghanistan;26/02/2020;398354280;50;0;NULL;NULL;NULL;NULL;126;0;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;
AFG;Asia;Afghanistan;27/02/2020;398354280;50;0;NULL;NULL;NULL;NULL;126;0;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;
AFG;Asia;Afghanistan;28/02/2020;398354280;50;0;NULL;NULL;NULL;NULL;126;0;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;NULL;
And my sql query is this:
LOAD DATA LOCAL INFILE 'C:\\Users\\Usuario\\Desktop\\CovidDeaths.csv' INTO TABLE coviddeaths
columns terminated by ';'
LINES TERMINATED BY '\r\n';
I have some alredy uploaded data to the coviddeaths table using the import wizards but the upload was really slow, so tried to finish importing using the LOAD DATA INFILE query.
To see how many lines have been alredy uploaded I used
select count(*) from coviddeaths;
And threw:
count(*)
11312
When I try to run the LOAD DATA LOCAL INFILE query, nothing happens. The mouse pointer spins for a second like it tries to run it but it doesnt add any additional row. It doesnt throw any errors like the ones I have read about Error Code: 1148. The used command is not allowed with this MySQL version. I also tried to place the csv file in the Uploads folder, where my Secure File Priv option pointed to in my.ini:
# Secure File Priv.
secure-file-priv="C:/ProgramData/MySQL/MySQL Server 8.0/Uploads"
It just does nothing. Any ideas?
Thanks in advance!
EDIT 2: Database Schema:
The error comes from the fact that both client and server must enable an option to allow local datafiles to be imported. If you use the command-line client, you would need to open the client like this:
mysql --local-infile -u root -p
In addition, the MySQL Server would need to be configured with the local-infile option.
The secure-file-priv is not needed, because that controls importing or exporting files on the server, not from the client.
See also ERROR 1148: The used command is not allowed with this MySQL version or my answer to "mysql 8.0" local infile fails I tried and display the settings. Could it be permission issues?
The error message is unusually obscure. MySQL error messages are usually more accurate and informative. I logged a bug in 2019 to request an improved error message, and they did fix it in MySQL 8.0.
I am trying to load data localy from pc to MySQL database ('texnologialogismikou') but I get a lot of errors. I searched a lot in forums and in MySQL site but I couldn't find a solution.
I tried to change variables, move the file in the Workbench directory and some other things but nothing worked.
load data local infile 'C:\Users\Mattheos\Desktop\ActualTotalLoad-10days.csv'
Into table texnologialogismikou.actualtotalload
fields terminated by ';' enclosed by '\"' lines terminated by '\n'
Some of the errors I got:
Error Code: 2. File 'C:ProgramDataMySQLMySQL Server 8.0Uploads' not found (OS errno 2 - No such file or directory)
Error Code: 1148. The used command is not allowed with this MySQL version
Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
P.S. I know that there are posts like this but this is the last thing I could do. I tried everything I could find and nothing worked.
On mySQL worckbench at the Manage Server Connections window -> Select your connection -> Go to the Advance tab and insert OPT_LOCAL_INFILE=1 in the others textinput.
The last error message is the relevant one:
Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
The --secure-file-priv option restricts from which directory files can be loaded, as explained in the documentation:
If set to the name of a directory, the server limits import and export operations to work only with files in that directory.
You can display the configured directory with:
show variables like "secure_file_priv";
Just move the file to import to that directory, and run the load statement again.
try mysqlimport
https://dev.mysql.com/doc/refman/8.0/en/mysqlimport.html
or Try community edition of tools like Pentaho ETL which will load data really fast.
Notepad++ has been giving me issues whenever I leave it for several minutes, seems to be going into some type of standby mode.
Whenever I go to save a file (connected to an FTP server via NppFTP), I get the errors below after the upload hangs for around 20 seconds. If I try again immediately after I see the error message, the transfer then goes through.
--
Failure retrieving contents of directory /public_html/etc
-OR-
Upload of C:\Users\Nathan\AppData\Roaming\Notepad++\plugins\config\NppFTP\Cache\filenameanddirectoryhere failed
Is there a way to prevent this? (get Notepad to ping the server every X seconds to prevent the connection timing out or something like that?)
you got the server and give command setenforce 0 . this is a command to turn off se linux.
Using PHPMyAdmin, I am trying to import a file via the following syntax...
LOAD DATA INFILE '/home/kim/development/www/ref_data/ISO_3100_Country_Codes.txt'
INTO TABLE country
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\r\n'
IGNORE 2 LINES
(name, code);
... but I get an error saying the file is not found (Errcode 13).
I am using Ubuntu 11.10 and the permissions on the file are 777.
I am logged in as root and the root user has the FILE privilege.
I looked at using the LOCAL keyword, but that threw a PHP Error (and I'd prefer not to have to haul the table over the client-server connection each time I want to import it).
The file system layout is per the Ubuntu default.
There have been no changes to the privileges since the server restarted, however I ran FLUSH PRIVILEGES just to be sure. It made no difference.
Any assistance appreciated!
Have you tried from mysql console? You will need the LOCAL keyword. Otherwise the command looks similar to what I did last week, should work ;-)
I have a LOAD DATA command that works fine in the MySQL terminal. It works fine in a test PHP file served from my local server. It works fine in phpMyAdmin on the same server. It inexplicably breaks down when run from Magento, also on the same server.
I have confirmed all methods are using the same login credentials. If I copy the failed command (including all previous queries from connection onwards) from the query log and paste into any other method it mysteriously works again. The query itself cannot be at fault.
Therefore I deduce the problem must be a permissions one. File privilege is set and works for other implementations on the same account. Magento is using pdo_mysql as it's connection. If I duplicate that in a test file it works. Magento must be setting some parameter that is interfering.
The error I get is SQLSTATE[42000]: Syntax error or access violation: 1148 The used command is not allowed with this MySQL version. I must use the "LOCAL" modifier keyword because I cannot guarantee the database server will be accessible.
The nearest previous question here on SO concerns drupal, the error is different but I recall drupal also uses pdo_mysql to connect, perhaps it is related. The only other mention of this error on Magento is this thread which also fails on a LOAD DATA LOCAL INFILE command.
Per #DeveloperChris' suggestion, you can enable SQL logging in Magento in the Varien_Db_Adapter_Pdo_Mysql class (in the lib\Varien path). Change the $_debug and $_logAllQueries class variables to true. You can also change the file path where the queries are logged in $_debugFile.
Don't forget to turn it off before production!
HTH,
JD