Skip to content

Instantly share code, notes, and snippets.

@dnaber-de
Created August 20, 2014 09:36
Show Gist options
  • Save dnaber-de/f65378d4dc5c9e5ab88d to your computer and use it in GitHub Desktop.
Save dnaber-de/f65378d4dc5c9e5ab88d to your computer and use it in GitHub Desktop.
How to copy a table in MySQL
CREATE TABLE IF NOT EXISTS dbname.new_tablename LIKE dbname.old_tablename;
ALTER TABLE dbname.new_tablename DISABLE KEYS;
TRUNCATE TABLE dbname.new_tablename;
INSERT INTO dbname.new_tablename SELECT * FROM dbname.old_tablename;
ALTER TABLE dbname.new_tablename ENABLE KEYS;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment