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
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 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.
I cant seem to use community server(or workbench for that matter) to use the Load local data infile command for csv. it always says cant use this command its not allowed on this version.
Ps I tried setting the local_infile global variable as 1 in the client cmd prompt but it still gives the same issue.Also i cant seem to give the parameters directly at start since the client opens on its own.(I dont have simple mysql command on windows only community server)
Why you want to use load local data infile command in Workbench? It already provides the option for table data import wizard.
Also, for the particular error, I tried following code and it worked for me:
(Before connecting to MySQL database type following)
mysql -u username -p --local-infile databasename
Enter Password:
Now, try using the database and importing the table.
MySQL> use databasename;
MySQL> load data local infile 'filename/filelocation.csv' into table tablename
-> fields terminated by ','
-> enclosed by '\r\n'
-> ignore 1 lines
-> (col1, col2, col3...);
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;
I am trying to understand Data Warehousing using the book 'Dimensional Data Warehousing with MySQL'. In Chapter 2 I need to insert the data to a table in MySQL.
I am trying this code
TRUNCATE customer_stg;
LOAD DATA INFILE 'customer2.csv'
INTO TABLE customer_stg
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES(
customer_number,
customer_name,
customer_street_address,
customer_zip_code,
customer_city,
customer_state
);
I am using lampp on Ubuntu 12.04.2. The file 'customer2.csv' has been copied to the folder '/opt/lampp/var/mysql/dw'.
In MySQL I am using an user 'dwid' with password as 'password'.
The file permissions of the csv file is set to
-rwxr-xr-x 1 mysql mysql 469 Oct 31 2005 customer2.csv
but still I am unable to load the data in the table. The loading is possible from the user 'root'.
From the MySQL 5.5 manual page:
LOCAL works only if your server and your client both have been
configured to permit it. For example, if mysqld was started with
--local-infile=0, LOCAL does not work. See Section 6.1.6, “Security Issues with LOAD DATA LOCAL”.
You should set the option:
local-infile=1
into your [mysql] entry of my.cnf file or call mysql client with the --local-infile option:
mysql --local-infile -uroot -pyourpwd yourdbname
You have to be sure that the same parameter is defined into your [mysqld] section too to enable the "local infile" feature server side.
It's a security restriction. I learned this from some other question in stackoverflow, I couldn't find the link, I had the answer saved. Hope this will help.