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表中?的詳細內容,更多請關注www.92cms.cn其它相關文章!