I have the following error mysql error #2000 - mysql

I get the error message. I am using phpAdmin
2000 - Can't find file 'c:/tmp/userlist.csv'.
LOAD DATA LOCAL INFILE 'c:/tmp/userlist.csv'
INTO TABLE users2
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\n';
I have googled and that error seems to be a lot of other things too.
It does exist as i have just pasted into windows and it opens the file.

With LOAD DATA LOCAL the file is read locally and it needs to be accessible by the client. You mentioned you are using phpMyAdmin (a MySQL client), so the file needs to be accessible from wherever phpMyAdmin is running from.
If phpMyAdmin isn't installed on your computer, then you need to upload the file to the server where it's located and change the file path accordingly.
Another solution would be to install a MySQL client on your computer to run the query, so it can read the file locally. I recommend MySQL Workbench.

The only thing I had to do in the end was press IMPORT inside phpMyadmin. It would have been nicer if somebody had told me that instead of mucking around for two days trying to import a csv via sqls.

Related

Unable to Upload a CSV to MySQL clean install - tried solutions for the errors with no avail

I'm having to create a local installation of MySQL for development of a Shiny App Dashboard for analytics (R language, my SQL knowledge is basic, for simple bulky queries that I then tune in R).
The deployed version will be on a MS SQL server, therefore I want to setup the basic tables I will use (which are in csv format, small extract of the real thing) to try and optimize my SQL query. I was initially using Postgres SQL but I discovered there are a few syntax differences and therefore I opted to restart and implement MySQL which to my knowledge should be the same with regards to query syntax.
I downloaded the MySQL community Windows installer and installed the
full version to my machine, with all default settings.
I created successfully the server (all default settings) and named it on MySQL Workbench
I then successfully created one test table with all the correct column names etc.
CREATE TABLE servername.test_table( col1 text,
col2 int,
col3 int,
col4 text,
...
col40 text);
Using the below code I tried uploading the CSV to the servername.test_table
LOAD DATA INFILE 'D:\Dropbox\R-Projects\SQL\SAMPLE DATASETS\DATA1.csv'
INTO TABLE servername.test_table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
The problem arise when I try to upload the csv to the desired table, I am getting:
Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
After some research, instead of meddling with access restrictions which I have no experience with nor fully setting up DBs. The simple possible solution would be to just keep the files in the directory that secure_file_priv would allow.
I ran the SQL command:
SHOW VARIABLES LIKE "secure_file_priv";
Got the directory: C:\ProgramData\MySQL\MySQL Server 8.0\Uploads and saved a copy of the csv file in that directory and then ran the following to try and upload the csv:
LOAD DATA LOCAL INFILE 'C:\ProgramData\MySQL\MySQL Server 8.0\Uploads\DATA1.csv'
INTO TABLE servername.test_table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
After the above, the following error became the new error:
Error Code: 2068. LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.
Back to research, I began to try and tinker with settings and MySQL command prompt.
Checked what was the server setting for the local_infile with SHOW GLOBAL VARIABLES LIKE 'local_infile'; as a query in MySQL Workbench, result was: Value - ON which to my understanding should have allowed the second attempt using the LOAD DATA LOCAL INFILE to have worked, it did not.
The below link suggested to add the following to the my.ini file.
ERROR 2068 (HY000): LOAD DATA LOCAL INFILE file request rejected due to restrictions on access
[client]
loose-local-infile=1
[mysqld]
local_infile=1
I did as well as restarted the MySQL80 service to see if it implemented... Tried uploading CSV again with no avail.
Could someone please help me upload this CSV so I can focus on my actual work? I've been at this for 2 days and it seems to be a common issue, yet I haven't seen and "dumb-down" step by step troubleshooting like I have presented.
If I may request, please try and provide a step by step approach on how to troubleshoot this. MySQL server mgmt skill are almost null, I'm used to have the access to the DB and simply querying.
Sorry for the long post, but I wanted to be as detailed as possible to show I've tried most of the solutions I've found with no success.
(not sure if this is pertinent: using a Threadripper 3960x workstation with 128GB ram, Windows 10 Pro, MySQL was fully installed in the same drive as Windows 10 Pro is)
Thank you for your time.
Quickest solution was to just deploy on Azure an MS SQL server and utilize the Azure Data Studio Extension called - SQL Server Import. For someone who just wants a server for testing and has to import CSV files that also uses enclosed speech marks. The deployment was quite fast when compared to trying to troubleshoot my local installation.

MySQL 8.0 / Workbench on Windows : Error Code: 2068. LOAD DATA LOCAL INFILE file request rejected due to restrictions on access

I'm trying to run a LOAD DATA LOCAL INFILE from a file on my C:\ drive into an existent table, logged at root in Workbench. I've researched it all afternoon, set local_infile=1, set secure_file_priv='', granted file access to my user, flushed privileges, tried forward and backslashes but can't seem to get round the problem. Error 2068 doesn't really tell you much in the manual either. Any other suggestions?
I'm running on Windows 10, latest MySQL versions (as of last week - its a fresh install) and the table I'm trying to insert into is really simple. Its clearly a permissions problem, but running as root on a windows instance where I'm admin surely shouldn't be a problem?
Code is "LOAD DATA LOCAL INFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/filename.csv' INTO TABLE tablename;
You should check that folder where the file you are trying to load is and confirm that you have the necessary permissions. If you have the permissions for the folder then check the file. You should used the properties options by right clicking on the folder or on the file.
Properties Window
EDIT:
Also try the instruction with only LOAD DATA INFILE without the LOCAL statement. That made it worked for me.

MySQL : error with --secure- file-priv while using USE LOAD DATA INFILE from R

Im running code in MYSQL works fine no problem.
But when i try to run the same code in R I get the error:
could not run statement: The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
I googled a bit and found alot of people having trouble with running this from their workbench. This isnt my problem though, i can insert from workbench. But I want to do everything from R.
The code im running is:
LOAD DATA
INFILE 'C:\\ProgramData\\MySQL\\MySQL Server 8.0\\Uploads\\Fred_mbf_meta_data.csv'
INTO TABLE fred.fredmetambf
FIELDS TERMINATED BY '\t'
IGNORE 1 LINES
(Title,Series_ID,Frequency,Units,Seas_adj,Start_Date,End_Date,Last_Updated);
I also tried adding >> LOCAL after LOAD DATA LOCAL INFILE.
But then I got the error: "The used command is not allowed with this MySQL version"
Is it game over?
As explained in the documentation, the secure-file-priv option restricts the directory from which files can be imported and exported.
You can use SHOW VARIABLES LIKE "secure_file_priv"; to find out what the current setting is.
Then, you can either move your import file to this directory, or disable the option (this requires modifying the init file and restarting the server).

Issue on Using LOAD DATA INFILE in Production Server

This code is working fine for me to load a huge .csv file into ecolo-dis-tbl table in Localhost using PHPMyAdmin and Wampserver
LOAD DATA INFILE 'C:/Data/Spreatsheets/Data-Single.csv'
INTO TABLE `ecolo-dis-tbl`
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Now can some one please let me know how I can address the file in production server like Godaddy? I mean instead of C:/Data/Spreatsheets/ what path should use if I load the file into the root
Using phpMyAdmin you can select the Import tab and work with the file directly from your local machine. To use the SQL code you've posted here, you'll first have to upload the file to your production database server by means of SSH, FTP, or whatever other way you put files on the server. Note that for some hosts the web server is on a different machine from the database server, so you have to make sure they go on the database server. Then just use the new path (maybe something like /home/suffii/Data-Single.csv) in place of C:/Data/Spreatsheets/Data-Single.csv.

File not found load data infile mysql

I keep getting an error 29 that says file is not found with the following syntax and I cannot figure out why:
LOAD DATA INFILE 'C:/Users/rkartj2/Desktop/LOINCSUNQUESTV2.txt'
INTO TABLE xiao
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Table xiao has been created in MySQL 5.7 and LOINCSUNQUESTV2.txt was an Excel spreadsheet created on a Windows machine.
While I have not used version 5.7 of Mysql yet, the error you are receiving is the same in previous versions. ERROR 29 (HY000): File 'C:/Users/rkartj2/Desktop/LOINCSUNQUESTV2.txt' not found
This may seem a bit misleading to a newb especially since you can go to your Desktop and see that the LIONSUNQUESTV2.txt file is there.
I see one of two possibilities here which is either that Mysql does not have permissions to access the file from the current directory or that it does not know that the file is on your local server.
You can try using LOAD DATA LOCAL INFILE. From dev.mysql
If that does not work, you need to move file to a location that mysql has access to, such as the Mysql data directory. In version 5.6 of a stock vanilla install it would be in this directory: C:\ProgramData\MySQL\MySQL Server 5.6. Try moving the file there. I believe that Mysql looks at this location by default, so I would change LOAD DATA INFILE 'C:/Users/rkartj2/Desktop/LOINCSUNQUESTV2.txt' to LOAD DATA INFILE 'LOINCSUNQUESTV2.txt'