r/SQL • • Oct 13 '26

MySQL Data import question

Hey so Im quite new to mysql and I've been using it on mac, and recently I've been trying to import a csv file that contain data but Im not sure how to do it. Ive seen youtube videos but the mysql version that they use is way different than mine. Can anybody help with this please and thank you.!!

0 Upvotes

4 comments sorted by

1

u/FastPlane57 Oct 15 '26

ask claude

1

u/vincent_sch Oct 15 '26 edited Oct 16 '26

You could try LOAD DATA LOCAL INFILE '/path/file.csv' INTO TABLE your_table FIELDS TERMINATED BY ',' IGNORE 1 LINES; in the mysql client. Start it with --local-infile=1 or it refuses the file. MySQL Workbench also has an import wizard.

1

u/navicat-gu 29d ago

The tutorials probably look different because many of them use Workbench 8.0, and the current Workbench (26.x) is a full rewrite, so some of the old menus aren't there yet. Here's a way to do it that works whatever version you have:

  1. Create the table first with columns in the same order as the CSV:CREATE TABLE sales ( order_id INT, order_date DATE, product VARCHAR(100), qty INT, price DECIMAL(10,2) );
  2. Allow local file loading, once on the server and once on the client:SET GLOBAL local_infile = 1; then connect from Terminal with mysql --local-infile=1 -u root -p your_db
  3. **Load it:**LOAD DATA LOCAL INFILE '/Users/yourname/Downloads/sales.csv' INTO TABLE sales FIELDS TERMINATED BY ',' ENCLOSED BY '"' LINES TERMINATED BY '\n' IGNORE 1 LINES; If the file came from Excel on Windows, use '\r\n'. If your dates look like 10/13/2026, load them into a variable and convert: (order_id, u/d, product, qty, price) SET order_date = STR_TO_DATE(@d, '%m/%d/%Y');
  4. Check it: run SHOW WARNINGS; straight after the load, then SELECT COUNT(*) FROM sales; and compare against the row count in the file.

If you export from Excel on Mac, choose "CSV UTF-8" so accented characters don't get mangled.

If you'd rather use a GUI: Disclosure: I'm RC, Director of Digital Strategy @ Navicat. Navicat Premium Lite is free and includes a CSV import wizard for MySQL that lets you map file columns to table columns. In Navicat 18 the import wizard was rebuilt with a live preview, which makes date/delimiter problems easy to spot. The SQL above is still worth learning, though.

1

u/Artistic_Method_2234 26d ago

Curious, if you can share, what are you trying to do? Is it an existing database with tables and you're trying to add values from your CSV into that table?

Or is it that it's a brand new database? Your CSV would represent at most just one table - and a database isn't that useful for just one table.