exporting data from table to .csv file - mysql

I'm trying to load data of a table into a csv file. However rows in file are broken in between. The data of table seems fine and there is no \n anywhere. Then why am I getting breaks in rows?
Query I'm executing is
select * from `abc_csv` into outfile '/home/abc.csv'
fields terminated by ',' lines terminated by '\n';
And the result I'm getting is:
A,B,C,D,
,E,F
While all these entries belong to the same record

Related

Exporting data to csv from mysql using SELECT INTO OUTFILE exports all columns in a single column

I am trying to export Mysql view data to csv. I have a large set of data in my database tables more than 15 million. I joined each and every table to a view and I just wanted to export it using the following query.
SELECT *
FROM database_name
INTO OUTFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/filename_1.csv'
FIELDS TERMINATED BY ','
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\r\n';
My problem is the generated csv file is not ordered. It is exporting all the columns in the view into a single column in csv file. How can I query it to get the data separately in different columns. Please help me with this. Thanks in advance.

How to upload more than 1000 entries using LOAD DATA INFILE?

I'm trying to import an csv file to my database table, the origin of this file was a previous database with the same structure. My issue is that it imports only 1000 rows instead of the whole 62k+ file. The script i'm using is:
LOAD DATA INFILE 'C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/covid19.csv'
INTO TABLE covid19.covid19
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 LINES
(id,date,iso2,iso3,country,continent,cases,deaths,population);
Some clients have a option, where they reduce the number of returned Rows with a LIMIT 1000.
You should check, how many rows you actually have with
SELECT COUNT(*) FROM covid19.covid19;
You should see the actual number of inserted rows, as the command didn't show any warnungs or errors.

MySQL query extracted to csv, but information is not in proper rows

I have written a query in MySQL and extracted it to a csv file.
The problem I have is that the values from the 3rd and 4th are not next to the values from the 1st and 2nd column, but one row below them.
SELECT * FROM KSK_Age2
INTO OUTFILE "C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Uploads\\kskAge.csv"
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\n';
This is the sql code I used to extract the query result. And I am also attaching a screenshot of the extraction in csv.
Thanks in advance!

Fastest way to load tablular data from a .csv file?

I have a database in mysql workbench, and i want to load data from .csv files. Now i'm doing with the option of 'Table Data Import Wizard' but takes to many time. My .csv files have million of rows, but each one takes about 12 hours to load. And i have about 100 files to load. My version of MySQL is the 8.0.
There is any way to load the data files fastest? Thanks in advice
You can try something like that:
LOAD DATA INFILE 'c:/myfile.csv'
INTO TABLE table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
Be careful with the values you give to FIELDS TERMINATED BY, ENCLOSED BY and LINES TERMINATED BY. Only use IGNORE 1 ROWS if you have a header line, containing the field names, for example.
And if you need to store the data on a remote server, you can use
LOAD DATA LOCAL INFILE 'c:/myfile.csv'
INTO TABLE table
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\n'
IGNORE 1 ROWS;
You can find more infos here.

Importing CSV infile

Ive tried to follow examples of how to import a csv infile with no luck. I have the following CSV-
And from what I understand, I need to set up a table in Workbench, with column names that match the CSV columns. I've done this:
Using this code-
LOAD DATA LOCAL INFILE 'C:/Users/Sam/Desktop/Eviction_Notices_2012to2017_AddressthruZip.csv' INTO TABLE evictions.test
FIELDS TERMINATED BY ','
ENCLOSED BY '"'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(Address, City, State, Zip);
I've had varying degrees of success. Right now, it only imports first 99 rows even though there is no limit specified.
Also, is there a way to copy your column names from excel easily into the alter table window, rather than creating each column name manually?
Am I doing something wrong here?