Home > Database > Mysql Tutorial > body text

How to Import CSV Data into MySQL Without Header Row and Starting from the Second Field?

Susan Sarandon
Release: 2024-11-12 13:16:02
Original
280 people have browsed it

How to Import CSV Data into MySQL Without Header Row and Starting from the Second Field?

Importing CSV Data into MySQL Without Header Row

You're facing challenges importing a CSV file into MySQL without header row and starting from the second field.

SOLUTION

To achieve this, utilize MySQL's ability to set column values during import. Since your id field is auto-incrementing, you can set it to null during import. MySQL will then assign appropriate values to it.

Implement the following code in the SQL tab of phpMyAdmin:

LOAD DATA INFILE 'path/to/file.csv' INTO TABLE your_table FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n' SET>
Copy after login

EXPLANATION

  • LOAD DATA INFILE imports data from a file into a table.
  • your_table is the table you want to import data into.
  • FIELDS TERMINATED BY ',': Fields are separated by commas.
  • LINES TERMINATED BY 'n': Lines are separated by newlines.
  • SET>: Sets the id field to null, allowing MySQL to auto-increment it.

The above is the detailed content of How to Import CSV Data into MySQL Without Header Row and Starting from the Second Field?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template