0

I'm new on mysql, i wanted to try to upload a csv file to mysql, i tried the Table Data Import Wizard (i watched it on youtube). But it looked like it takes forever to import the data. I left it few hours and it's still loading, so i just cancelled it.

Loading Image:

this

The 2nd way i tried the SQL command line(from youtube again) and tried to do this:

create table bikes
ride_id varchar(10),
rideable_type varchar(30),
started_at date,
ended_at date,
start_station_name varchar (50),
start_station_id varchar (10),
end_station_name varchar (50),
);

Actually i dont really understand how importing stuff in MySQL works, is there any simple way to import csv to MySQL just like how python read csv's?

Thank You

  • How many rows are in the CSV? – matigo Aug 25 '21 at 12:53
  • @matigo 82550 rows – dgrszombie315 Aug 25 '21 at 12:54
  • That's not too crazy. One option would be to open the CSV in a spreadsheet application, and construct 17 `INSERT` statements containing the CSV rows into `VALUES` with 5,000 records ... except the last, which will have 2,550 records. Alternatively, you can [use `LOAD DATA LOCAL INFILE`](https://stackoverflow.com/a/6605783/14952832), which is a more common method. – matigo Aug 25 '21 at 12:59

1 Answers1

1

I think one of the fastest way of uploading CSV file to MySQL is using Load Data. You should upload your csv file on your mysql path '/var/lib/mysql/your_data.csv' using software like WinSCP and use below query:

Then you can use load data.

LOAD DATA INFILE '/var/lib/mysql/your_data.csv'  ---path of your file in server, it could be '/var/lib/mysql-files/your_data.csv'
IGNORE INTO TABLE your_table
FIELDS TERMINATED BY ';' 
LINES TERMINATED BY '\n'
IGNORE 1 ROWS
(id,x,y,your_colums);
Ergest Basha
  • 7,870
  • 4
  • 8
  • 28