Home >Database >Mysql Tutorial >How Can I Import Data from a Text File into My MySQL Database?

How Can I Import Data from a Text File into My MySQL Database?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-12-03 02:01:09139browse

How Can I Import Data from a Text File into My MySQL Database?

Importing Data from a Text File into a MySQL Database

To import data from a text file into your MySQL database, you can utilize the LOAD DATA INFILE command. Here's a step-by-step guide:

Step 1: Prepare your text file

Review the contents of your text file and ensure it contains the data in a tab-delimited format, with one row per line.

Step 2: Establish a MySQL connection

Connect to your MySQL database using a client tool like MySQL Workbench or the MySQL command line.

Step 3: Execute the LOAD DATA INFILE command

Execute the following command in the MySQL query editor:

LOAD DATA INFILE '/path/to/your/text_file.txt' INTO TABLE PerformanceReport;

Replace "/path/to/your/text_file.txt" with the actual path to your text file.

Step 4: Verify the import

After executing the command, check if the data was successfully imported by running the following query:

SELECT * FROM PerformanceReport;

This will display all the rows in your PerformanceReport table to confirm the import.

The above is the detailed content of How Can I Import Data from a Text File into My MySQL Database?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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