MySQL - export data and ignore the primary key. Then import using auto zoom

I have a table with a primary key in the auto-increment column "id" and the column "data"

Table of Contents:

id | data 1 | aaaaa 2 | bbbbb 3 | whatever :P 5 | dang 99 | hello 

As you can see, there are 5 lines. the identifier is 1,2,3,5,99 (no NO id = 4 or id = 6 to 98).

How can I export this table and then import it into another table (same structure, of course), and the identifier will get the values ​​1,2,3,4,5 instead of 1,2,3,5,99.

(or import them into a table that already has data, and the imported identifiers will take any values ​​from this auto_increment value and continue?)

Note. If there is any solution for PhpMyAdmin, welcome it.

-Sorry for bad English! (Ops feel free to edit)

+4
source share
2 answers

Create a table with the same layout. Then:

 INSERT INTO new_table (data) SELECT data FROM old_table; 

This will copy only the data to the new table. Since the id column is auto_increment, it will add identifiers from one up.

+8
source
 INSERT INTO newTable (data) SELECT data FROM oldTable; 
+5
source

Source: https://habr.com/ru/post/1399805/


All Articles