Cannot Remotely Load CSV into MySQL - mysql

So I'm remotely accessing a MySQL server and I've tried everything under the sun in order to invoke the following command:
LOAD DATA INFILE 'C:\Users\user1\Desktop\csv\mycsv.csv'
INTO TABLE mytable
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
However I get the following error:
Error Code: 1290. The MySQL server is running with the --secure-file-priv
option so it cannot execute this statement
I then tried modifying the statement and adding LOCAL as such:
LOAD DATA LOCAL INFILE 'C:\Users\user1\Desktop\csv\mycsv.csv'
INTO TABLE mytable
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
and received the following error
Error Code: 1148. The used command is not allowed with this MySQL version
I ran the following 2 commands to check my global variables pertaining to these two errors which returned the following:
SHOW VARIABLES LIKE "secure_file_priv";
Returns NULL
And
SHOW GLOBAL VARIABLES LIKE 'local_infile';
Returns ON
I contacted the system administrator to change the my.ini. I set my local secure_file_priv to a directory on my PC with no luck. I have no access to the PC the server lies on so I can't move files to any local directories, only remotely accessed ones.
I have referred to every solution under How should I tackle --secure-file-priv in MySQL? and How to import CSV file to MySQL table with no luck.
If you have any other ideas please let me know. Thanks

secure_file_priv is set at start up and can not be dynamically changed. Make the following addition to your my.ini file, then restart mySQL.
secure-file-priv="C:\Users\user1\Desktop\csv\"

Related

How do I change the secure-file-priv variable for MySQL on Mac?

Been trying to solve this problem for hours now and nothing seems to be working. I am trying to set up MySQL to be able to upload csv files automatically in code like this:
LOAD DATA INFILE '/Users/aubrey/Documents/dbproject/dates_table.csv'
INTO TABLE dates
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
This gives me the error:
Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
I read up on stackoverflow and mysql docs about the secure-file-priv options. The result of SHOW VARIABLES LIKE "secure_file_priv"; is NULL. So I need to change that to be the directory I want in the my.cnf file. Cool.
I did that.
And after restarting the server, that shows up in the workbench Options File (Administration tab, under Instances)
But when I run SHOW VARIABLES LIKE "secure_file_priv"; again, I still get NULL
I've tried both secure-file-priv and secure_file_priv, both show up in the options correctly but give a null in SHOW VARIABLES.
What am I doing wrong?
Running Ventura 13.1, MySQL 8.0.32ARM64

Load data infile does nothing

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.

How can I load local data in MySQL Workbench 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.

Mysql server showing secure-file-priv error message even though secure-file-priv is set

I am running mysql version 5.7.27 for Linux on a remote server.
I have a php Script that should load some big csv files into a database via following code
$query = "LOAD DATA INFILE
'C:/some/big/file/file.csv'
REPLACE INTO TABLE csv_table
CHARACTER SET UTF8
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES";
The script is running normally but mysql sends out the following error:
Errormessage: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
I already did a lot of googling about this error and eventually found some helpful tips about how to set the variable and what to set:
https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_secure_file_priv
I also learned mysql will look at 3 places for the configuration:
/etc/my.cnf
/etc/mysql/my.cnf
/usr/local/etc/my.cnf ~/.my.cnf
in respective order.
The my.cnf includes etc/mysql/mysql.conf.d file so I put the following line there
[mysqld]
secure_file_priv = '/home/my/folder/'
When I check the setting via
SHOW VARIABLES LIKE 'secure-f%';
I get the correct value!
But when I try to execute the script, I still receive the same old error message. Since the setting is correctly printed, I am not sure what to make of this.
Please help me figure out how to get rid of this error. Thanks
EDIT:
Thanks for the hint! It's embarassing but it was really like you said. I tested locally (worked) and copy pasted the code onto the server, where there is no C:/ .. of course. Thank you.
After this I got a different error which could be solved with the help of this:
LOAD DATA INFILE Error Code : 13

MySQL into output file error

I am very new with SQL but I have to extract some fields of a table stored in a sql file.
I have installed mysql and create the database and source the file. Now I wanted to execute a sql request in order to read all the elts of the table, extract the interesting fields and write them into cvs file:
SELECT * INTO OUTFILE '/home/cr/database/Dump2/program_info.csv' FIELDS TERMINATED BY ',' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\n' FROM program_info;
When running the command I have the following error message:
ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
Does anyone knows how to solve it ?
I have struggled with this message all the afternoon but could not .
I am working on Linux ubuntu and my config file is /etc/my.cfg
[mysqld]
read-only = 0
secure-file-priv = ""
Thank you for your help
MySQL is actually working as intended. The MySQL server booted with the --secure-file-priv option which basically restricts you from saving output into random directories. You need to check the startup parameters.
To do so, run the following command in the MySQL shell:
SHOW VARIABLES LIKE 'secure_file_priv';
The output would be what the MySQL Server currently thinks is the permitted location. You should be able to save your output to this location.
To disable the restriction, you need to edit the configuration file that declares it and restart the MySQL Server after changing the option.
MySQL could be reading the my.ini (or my.cnf) configuration file from a variety of locations. See Using Option Files for more information.