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