MySQL Table Import Quick Methods

With either the command-line tool or a graphical tool in MySQL, you can import data from one table to another using the following methods:

  1. The INSERT INTO SELECT statement is used to insert data into an existing table. First, a target table is created using the CREATE TABLE statement, and then data is selected from a source table and inserted into the target table using the INSERT INTO SELECT statement.
CREATE TABLE new_table LIKE old_table; 
INSERT INTO new_table SELECT * FROM old_table;
  1. The LOAD DATA INFILE statement is used to import data from a file into a table. Save the data to a text file first, then use the LOAD DATA INFILE statement to read the data from the file and import it into the table.
LOAD DATA INFILE 'path/to/file' INTO TABLE table_name;
  1. Utilize MySQL import tools: MySQL offers tools such as mysqlimport and MySQL Workbench for easily importing data from files into tables. These tools can be used through either command line or graphical interface.

Regardless of the method used, it is essential to ensure that the structure of the source data and the target table are consistent to avoid importing errors.

bannerAds