I am using Mac with mysql workbench 8.0.19
when i run this
LOAD DATA LOCAL INFILE '~/Users/raianazaman/Desktop/DataBase/Sample.txt' INTO TABLE employee
FIELDS TERMINATED BY ','
ENCLOSED BY ''
LINES TERMINATED BY '\n'
IGNORE 0 LINES;
i get this error:
Error Code: 3948. Loading local data is disabled; this must be enabled on both the client and server sides
I have run this:
SHOW GLOBAL VARIABLES LIKE 'local_infile';
and it shows: 'local_infile','ON'
I have run this: SHOW GLOBAL VARIABLES LIKE 'local_infile'; and it shows: 'local_infile','ON'
I think you can run mysql --local-infile=1 -u root -p and try to load file again. It works for me.
Related
I am using Amazon RDS MySql for data storage. I am able to load data by specifying the column values, however, when I try to load the data from my local machine to MySql, it fails with
Error: 2068.
LOAD DATA LOCAL INFILE '/Users/priya/Documents/Atlas/data/The_Atlas_0820.csv' INTO TABLE schedule
FIELDS TERMINATED by ','
ENCLOSED by '"'
LINES TERMINATED by '\n' IGNORE 1 LINES (Carrier1, FlightNo1, DupCar1,DupCar2, DupCar3,
DupCar4,DupCar5, DupCar6,DupCar7, DupCar8,DepAirport, ArrAirport);
Error Code: 2068. LOAD DATA LOCAL INFILE file request rejected due to restrictions on access.
I also checked SHOW GLOBAL VARIABLES LIKE 'local_infile'; and it is set to "ON".
If i use Terminal to open a connection with MySql and execute the command there, it works ok.
$ ./mysql -h <hostname> -P 3306 --local_infile=1 -u <username> -p
But how to make it work in MySql Workbench.
It seems that there is a bug in MySQL Workbench for LOAD DATA LOCAL INFILE, check if the workaround in this link works for you:
MySQL Workbench 8.0 restricts usage of LOAD DATA LOCAL INFILE
or there is another solution that seems to work here:
Workbench 8.0.12 no longer allows LOAD DATA LOCAL INFILE
Adding what worked for me here, I was able to find a working solution through the links #Zacca provided, but I had to dig through solutions that didn't work, and I thought I'd repost here in case those links die at some point.
First, if I ran SHOW GLOBAL VARIABLES LIKE 'local_infile'; I can see that INFILE is enabled. However, I was still getting "ERROR CODE 2068"
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| local_infile | ON |
+---------------+-------+
I was able to resolve this by editing the connection string in MySQL workbench by navigating to Home, then:
Edit Connection > Advanced > Copy OPT_LOCAL_INFILE=1 into Others box on a new line
Then restart the connection. After that, LOAD LOCAL INFILE runs without error.
Also, as a side note, before I found this solution, I found I could run the LOAD LOCAL INFILE command from R without issue, which helped me isolate the client as the issue, as opposed to a security/permissions related problem.
The solution that worked for me is from the workarounds shared in the link:
Workbench 8.0.12 no longer allows LOAD DATA LOCAL INFILE as shared by #Zacca.
Steps for Mac:
Create a my.cnf file with the following statements at the path: /etc.
I created my.cnf file using root user.
[client]
port = 3306
[mysqld]
port = 3306
secure_file_priv=''
local-infile = 1
Set the my.cnf file as the default configuration file in MySql Workbench.
Click the Wrench icon next to Instance.
Under configuration file, enter the path to my.cnf file: /etc/my.cnf.
Restart the MySQL server workbench.
Try the following statements in MySQL Workbench:
SHOW VARIABLES LIKE "local_infile"; //Should be ON
SHOW VARIABLES LIKE "secure_file_priv"; //Should have no values (not NULL but blank)
Load the data.
LOAD DATA LOCAL INFILE '<path>/file.csv' INTO TABLE <tablename>
FIELDS TERMINATED by ','
ENCLOSED by '"'
LINES TERMINATED by '\n' IGNORE 1 LINES;
Using LOCAL keyword, loading is successful.
However, without LOCAL keyword, I get access error.
Error Code: 1045. Access denied for user 'admin'#'%' (using password: YES)
After beating my head around this for an hour, I switched back to MySQL Workbench 6.3.
Bliss.
I'm trying to bypass the -secure-file-priv option that MySQL has enabled to export a table into a .csv file.
I've been running SELECT * FROM final_table INTO OUTFILE 'test.csv' FIELDS ENCLOSED BY '"' TERMINATED BY ';' ESCAPED BY '"' LINES TERMINATED BY '\r\n'; into the terminal, but it has been returning The MySQL server is running with the --secure-file-priv option so it cannot execute this statement
Previously, I bypassed this error when importing files by running LOAD DATA LOCAL INFILE instead of LOAD DATA INFILE which had the same error and was wondering if there was a way to do it with exporting as well.
Thanks!
Answering my own question since I found a solution that might help out other people.
mysql -u root -p [database] -e '[SELECT * FROM TABLE_NAME]' > data_export.csv
got me exactly what I needed without disabling secure-file-priv!
I am trying to run this query
LOAD DATA LOCAL INFILE "C:/myfile.txt"
IGNORE INTO TABLE mydb.mytable
FIELDS TERMINATED BY ';'
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
If I run it in MySQL Workbench (v8.0.16) I get an error
Error Code: 1148. The used command is not allowed with this MySQL version
However if I run it in SQLYog (Professional v12.09) it works fine.
I am running both bits of code using the same computer, with the same user, on the same database running on the same server.
That server has local_infile = 1
As far as I can tell the only difference in these queries is the SQL Client being used.
My assumption is that it is the connection string / settings that is different between the two as a default, however I can't find any documentation on this.
Why would this be and how can I fix it?
Thanks
In linux you have to start mysql client in command line as.
mysql -u root -ppassword --local-infile=1
you should also set local_infile = 1 in configuration file
I'm trying to load data into a MySQL table using LOAD DATA LOCAL INFILE using:
LOAD DATA LOCAL INFILE 'f.csv' INTO TABLE tableName
FIELDS TERMINATED BY ';'
LINES TERMINATED BY '\\r\\n'
IGNORE 1 LINES
(C1, C2, C3, C4)
SET cmj = REPLACE(#cmj,',','.');
OS : Ubuntu 14.04
MySQL : 5.7
In file my.cnf I have this config:
[mysqld]
local-infile=1
[mysql]
local-infile=1
[client]
loose-local-infile=1
local-infile=1
I'm getting the following error:
Message: SQLSTATE[42000]: Syntax error or access violation: 1148 The
used command is not allowed with this MySQL version, query was: LOAD
DATA LOCAL INFILE 'f.csv' INTO TABLE tableName FIELDS TERMINATED BY
';' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (C1, C2, C3, C4)
I think the problem is related to new line in MySQL
Thanks for your help
EDIT
In my file.csv I have two lines (header + values). If I update my request "IGNORE 1 LINES" to "IGNORE 0 LINES" the first line (header) is inserted.
All lines are considered as one line!!!!!
use --local-infile while connecting database.
mysql -hhostname -uusername -p --local-infile test -A
Hope this helps.
According to the MySQL reference manual v5.7, the error you received can result from LOCAL file capability being disabled either on the server or client side.
Running mysql with the --local-infile option will enable LOCAL capability on the client side, but this won't help if it's disabled on the server, where it's controlled by the system variable local_infile. The easiest way to fix this is to reset the system variable during runtime with the SET command:
SET GLOBAL local_infile = 1;
Note: In later versions of MySQL you can make the variable change persist over server restarts with the command
SET PERSIST local_infile = 1;
mysql> LOAD DATA INFILE '/abc.txt' INTO TABLE test1 FIELDS TERMINATED BY '|';
ERROR 13 (HY000): Can't get stat of '/abc.txt' (Errcode: 2)
I used LOAD DATA as per the syntax. But getting the above error. can anybody tell what is the error..!?
I tried searching google dev.mysql can't find what error it is??
Thanks in advance
If the file is on your MYSQL server try using the full path.
LOAD DATA INFILE '/var/tmp/abc.txt' INTO TABLE test1 FIELDS TERMINATED BY '|';
If the file isn't on the server and it is on your local machine, and your user has access to SCP files between the servers ( try this
scp abc.txt mysqlserver:
) then you should be able to do this (using full path again) ..
LOAD DATA LOCAL INFILE '/var/tmp/abc.txt' INTO TABLE test1 FIELDS TERMINATED BY '|';
If that doesn't work.. try renaming the file to test1.txt and using the 'mysqlimport' command?
Login to the mysql console using the following flag:
mysql -uroot -p --local-infile
and then enter the password.
After that execute the load data command as follows:
LOAD DATA LOCAL INFILE '/abc.txt' INTO TABLE test1 FIELDS TERMINATED BY '|';