Home  >  Article  >  Database  >  How to import txt text data in mysql

How to import txt text data in mysql

coldplay.xixi
coldplay.xixiOriginal
2020-08-25 09:32:555591browse

Mysql method of importing txt text data: first create the database and table; then create the table and write the data into a [pet.txt] text; finally use the command to import the database.

How to import txt text data in mysql

Mysql method of importing txt text data:

First create the database and table:

mysql> create database menagrie;

Then create the table:

 mysql> CREATE TABLE pet (name VARCHAR(20), owner VARCHAR(20),
        species VARCHAR(20), sex CHAR(1), birth DATE, death DATE);

Then write the following data into a pet.txt text:

Fluffy Harold cat f 1993-02-04 \N
Claws Gwen cat m 1994-03-17 \N
Buffy Harold dog f 1989-05-13 \N
Fang Benny dog m 1990-08-27 \N
Bowser Diane dog m 1979-08-31 1995-07-29
Chirpy Gwen bird f 1998-09-11 \N
Whistler Gwen bird \N 1997-12-09 \N
Slim Benny snake m 1996-04-29 \N

Use the following command to import the database:

mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet;

You will get the result after completion:

How to import txt text data in mysql

Related learning recommendations: mysql learning

The above is the detailed content of How to import txt text data in mysql. 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