Get the App
SLTechnology News&Howtos  ›  Database  › 

How to import data to mysql using load data

Shulou Source: shulou.com Published: 2022-05-31 15:59:54 10月02日 Update

Editor to share with you how to use load data to import data into mysql. I hope you will get something after reading this article. Let's discuss it together.

In addition to importing data into mysql in mysqlimport mode, more load data statements are used, which are similar to Oracle's sqlload. Detailed usage can be viewed at help load data.

1. Prepare to import data

[root@D2-LZY245 ~] # cat / tmp/emp.txt

100,Steven,King,24000.00

101,Neena,Kochhar,17000.00

102,Lex,De Haan,17000.00

103,Alexander,Hunold,9000.00

104,Bruce,Ernst,6000.00

105,David,Austin,4800.00

106,Valli,Pataballa,4800.00

107,Diana,Lorentz,4200.00

108,Nancy,Greenberg,12008.00

109,Daniel,Faviet,9000.00

110,John,Chen,8200.00

2. Create InnoDB engine table

Mysql > create table emp1 (

-> employee_id int (10)

> first_name varchar (50)

> last_name varchar (50)

-> salary decimal (10jue 2) engine=innodb charset=utf8

Query OK, 0 rows affected (0.00 sec)

3. Import data

Mysql > load data infile'/ tmp/emp.txt' into table emp1 charset utf8 fields terminated by','

Query OK, 11 rows affected (0.00 sec)

Records: 11 Deleted: 0 Skipped: 0 Warnings: 0

4. View the results

Mysql > select * from emp1

+-+

| | employee_id | first_name | last_name | salary | |

+-+

| | 100 | Steven | King | 24000.00 | |

| | 101 | Neena | Kochhar | 17000.00 | |

| | 102 | Lex | De Haan | 17000.00 | |

| | 103 | Alexander | Hunold | 9000.00 | |

| | 104 | Bruce | Ernst | 6000.00 | |

| | 105 | David | Austin | 4800.00 | |

| | 106 | Valli | Pataballa | 4800.00 | |

| | 107 | Diana | Lorentz | 4200.00 | |

| | 108 | Nancy | Greenberg | 12008.00 | |

| | 109 | Daniel | Faviet | 9000.00 | |

| | 110 | John | Chen | 8200.00 | |

+-+

11 rows in set (0.00 sec)

After reading this article, I believe you have a certain understanding of "how to import data into mysql using load data". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Tags: Data more articles functions done engine way knowledge results Industry sentences Information channels channels preparation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Redmi macOS Linux vpn