Home > Database > Mysql Tutorial > How to Import a CSV File with Multiline Text Data into MySQL?

How to Import a CSV File with Multiline Text Data into MySQL?

Susan Sarandon
Release: 2025-01-01 11:32:10
Original
462 people have browsed it

How to Import a CSV File with Multiline Text Data into MySQL?

Question on Importing a CSV File into MySQL Table

Problem:

Importing a CSV file into a MySQL table fails, resulting in an empty table filled with NULL values. The source file contains multiline text data, leading to incorrect data parsing.

Solution:

When importing a CSV file into a MySQL table, consider the following steps to handle multiline text data and ensure correct data placement:

  • Use mysqlimport utility to import the table data into the database. This tool provides more control over the import process.

    mysqlimport --ignore-lines=1 \
            --fields-terminated-by=, \
            --local -u root \
            -p Database \
             TableName.csv
    Copy after login
    • --ignore-lines=1: Ignores the first line of the CSV file, assuming it contains column names.
    • --fields-terminated-by=,: Specifies that fields are separated by commas.
    • --local: Uses local files instead of remote ones.
    • -u root -p: Prompts for the root password.
    • Database: Name of the database into which the table will be imported.
    • TableName: Name of the table to be imported.
  • Specify additional import options if necessary:

    • --fields-enclosed-by=: Value used to enclose field values (e.g., double quotes).
    • --lines-terminated-by=: Value used to terminate lines (e.g., "n").

By following these steps, you can effectively import CSV files with multiline text data into MySQL tables, ensuring accurate data representation.

The above is the detailed content of How to Import a CSV File with Multiline Text Data into MySQL?. 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