Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MySQL

ขั้นตอนการอัปโหลดข้อมูลลงตาราง MySQL ด้วย mysqlimport

ขั้นตอน 3 ขั้นตอนสำหรับการนำเข้าข้อมูลด้วย mysqlimport

ขั้นตอนที่ 1 - สร้างตาราง (Creating the table)

ต้องมีตารางใน MySQL ที่จะนำเข้าข้อมูลก่อน ใช้คำสั่ง CREATE TABLE

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)

ขั้นตอนที่ 2 - สร้างไฟล์ข้อมูล (Creating the data file)

สร้างไฟล์ข้อมูลที่มีข้อมูลคั่นด้วยแท็บ (tab-delimited) ชื่อไฟล์ต้องตรงกับชื่อตาราง

ไฟล์ student_tbl.txt:

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

ขั้นตอนที่ 3 - นำเข้าข้อมูล (Uploading the data)

ใช้คำสั่ง 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)