How do I delete only the results of one table in a database in MySQL and replicate to another remote empty table with the same structure?

This is a long sentence, does anyone know?

+2


a source to share


2 answers


To create dump

:

mysqldump --user [username] --password=[password] --no-create-info [database name] [table name] > /tmp/dump.sql

      



Recovery:

mysql --u [username] --password=[password] [database name] [table name] < /tmp/dump.sql

      

+3


a source


Something like that:

SELECT *
INTO new_table_name [IN externaldatabase]
FROM old_tablename
WHERE 1=0

      

I'm not sure if this works with My SQL, but you get the idea.

It does NOT duplicate PCs, FKs, indexes, stored procedures, or whatever. Just columns and data types.

W3Schools

D'o



I must have misunderstood your question. It's almost 3 hours before bed.

So, there might be a better way to do it, but this will get the job done.

SELECT  CONCAT('INSERT INTO (COL1, COL2) VALUES (',COL1,COL2,');');

      

You will need to add 'for some data types.

SELECT  CONCAT('INSERT INTO (COL1, COL2) VALUES (',COL1,''' ''',COL2,');');

      

Take the output and run on the remote db.

+1


a source







All Articles