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

View all comments

1

u/navicat-gu Oct 20 '26

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.