Loading local data on mysql community server/workbench - mysql

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...);

Related

How to migrate data from an Informix database to MySQL

We have to migrate data from an Informix database to a MySQL database.
Help me how we can achieve it?
What steps or commands I have to use it? If you have any document or reference link that would be very much helpful.
Step1: login to Informix and run the unload command. It will create a backup file named "file1" at current location under export directory.
UNLOAD to 'export/file1' SELECT * FROM db1.table1
Step2: Create table1 in MySQL Database.
Step3: Login to MySQL Database and set the global variable.
mysql> SET GLOBAL local_infile=1;
mysql> quit
Step4: Login to MySQL Database using below command
mysql --local-infile=1 -u root -p
Step5: Load the data into MySQL Databse using LOAD DATA command
LOAD DATA LOCAL INFILE '/export/file1'
INTO TABLE table1
FIELDS TERMINATED BY '|'
LINES TERMINATED BY '\n';

Error Code: 2068 while loading csv file into MySql

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.

MySQL LOAD DATA LOCAL INFILE difference in Clients

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

Can not import big CSV to MySQL 5.6 even using --local-infile=1

I have a CSV file with about 600MB size. I wanted to import it using SSH into MySQL 5.6, and as I read, I can use LOAD command in MySQL 5.7
Due to it, I used --local-infile=1 when connecting to MySQL on my server like this:
mysql -u mydb -p --local-infile=1;
And after that, I ran my code like this:
LOAD DATA LOCAL INFILE 'myfile.csv'
INTO TABLE mytable
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\'
(col1,col2,col3);
But still I am getting this error whereas I read everywhere I can solve the problem using --local-infile=1
ERROR 1148 (42000): The used command is not allowed with this MySQL version
Do you know what is the matter?
It only works if the Server allows this:
see: https://dev.mysql.com/doc/refman/5.6/en/load-data.html
The LOCAL keyword affects expected location of the file and error
handling, as described later. 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”.
Change your Php settings execution time to unlimited and import using
//Process the score on csv
$location = $_FILES['fileField']['tmp_name'];
$file = fopen($location, "r");
while (($csvfile = fgetcsv($file, 10000, ",")) !== FALSE) {
$firstClm = $csvfile[0];
$secondClm = $csvfile[1];
$thirdClm = $csvfile[2];
//Insert to database
}

Import data to MySQL using CSV

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.