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.
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:
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!