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

王林
发布: 2023-09-07 15:57:05
转载
838 人浏览过

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

通过mysqlimport的帮助,我们可以将数据上传到多个MySQL表中。下面的示例中有说明:

示例

假设我们想要从两个数据文件student1_tbl.txt上传以下数据:

1     Saurav     11th
2     Sahil      11th
3     Digvijay   11th
登录后复制

还有 House.txt

1   Furniture
2   Television
3   Refrigerator
登录后复制

以下是我们要上传上述数据的 MySQL 表 -

mysql> DESCRIBE Student1_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)

mysql> DESCRIBE House;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Sr    | int(11)     | YES  |     | NULL    |       |
| Name  | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)
登录后复制

现在,借助以下命令,我们可以将数据上传到这两个表中 -

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

mysql> Select * from House;
+------+--------------+
| Sr   | Name         |
+------+--------------+
| 1    | Furniture    |
| 2    | Televisoin   |
| 3    | Refrigerator |
+------+--------------+
3 rows in set (0.00 sec)

mysql> Select * from student1_tbl;
+--------+----------+-------+
| RollNo | Name     | Class |
+--------+----------+-------+
| 1      | Saurav   | 11th |
| 2      | Sahil    | 11th |
| 3      | Digvijay | 11th |
+--------+----------+-------+
3 rows in set (0.00 sec)
登录后复制

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

来源:tutorialspoint.com
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板