首页  >  文章  >  数据库  >  如何使用mysqlimport将数据上传到MySQL表中?

如何使用mysqlimport将数据上传到MySQL表中?

WBOY
WBOY转载
2023-09-05 13:37:021281浏览

如何使用mysqlimport将数据上传到MySQL表中?

For uploading the data into MySQL tables by using mysqlimport we need to follow following steps −

Step-1 − Creating the table

first of all, we need to have a table in which we want to upload the data. We can use CREATE TABLE statement for creating a MySQL table. For example, we created a table named ‘student_tbl’ as follows −

mysql> DESCRIBE Student_tbl;
+--------+-------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| RollNo | int(11)     | YES  |     | NULL    |       |
| Name   | varchar(20) | YES  |     | NULL    |       |
| Class  | varchar(20) | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
3 rows in set (0.06 sec)

Step-2 − 创建数据文件

现在,在这一步中,我们需要创建一个数据文件,其中包含以制表符分隔的字段。由于我们知道数据文件的名称必须与MySQL表的名称相同,因此我们将创建名为“student_tbl.txt”的数据文件,其中包含以下数据:

1 Gaurav    10th
2 Rahul     10th
3 Digvijay  10th

Step-3 − 上传数据

现在通过使用mysqlimport命令,我们可以导入这个文件 −

C:\mysql\bin>mysqlimport -u root query C:/mysql/bin/mysql-files/student_tbl.txt
query.student_tbl: Records: 3 Deleted: 0 Skipped: 0 Warnings: 0

现在通过以下查询的帮助,我们可以看到数据已经上传到表中 −

mysql> Select * from student_tbl;
+--------+----------+-------+
| RollNo | Name     | Class |
+--------+----------+-------+
|     1  | Gaurav   | 10th  |
|     2  | Rahul    | 10th  |
|     3  | Digvijay | 10th  |
+--------+----------+-------+
3 rows in set (0.00 sec)

以上是如何使用mysqlimport将数据上传到MySQL表中?的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除