透過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中文網其他相關文章!