15

How can I copy a schema to another schema I've created in Datagrip, essentially creating a clone of the original. For some reason my CMD prompt is not set for MySQL, and I have not found the way to do it via the Datagrip user interface.

Edward
  • 3,292
  • 1
  • 27
  • 38
AsapHogFtw
  • 181
  • 1
  • 1
  • 8
  • Database Tools → Copy Data Sources to Clipboard and then Import from Clipboard. images for that you find on the homepage https://www.jetbrains.com/de-de/datagrip/features/dbobjects.html search for Datenquellen kopieren – nbk Apr 29 '20 at 23:48

2 Answers2

6

There can be two ways.

  1. Reliable and with data, but requires my_sqldump. Context menu of the schema -> Export with mysql_dump. After that, on your new schema go to Context menu -> Restore with mysql_dump.

enter image description here

  1. Works if your schema does not contain some very specific objects: LOGFILE GROUP, SERVER, SPATIAL REFERENCE SYSTEM, TABLESPACE. And with no data. Go to the context menu of the schema -> Sql Scripts -> SQL generator. There you will see the script to create the schema from scratch. Just run it on your new schema.

enter image description here

moscas
  • 9,064
  • 36
  • 42
  • the first solution as some issue reported on datagrip, **sometimes mysqldump option disappear**, you have to check the URL in database properties. **Check jet-brains support page:** https://intellij-support.jetbrains.com/hc/en-us/community/posts/360006931279-mysqldump-is-missing-for-mysql-database – Mike D3ViD Tyson Dec 02 '20 at 15:24
5
  1. If you want to clone database structure only do this
  • Step 1: Choose the database which you want to clone.

  • Step 2: Right click => SQL Scripts => Generate DDL to Clipboard.

  • Step 3: Create a console file in destination DB => Paste DDL from the clipboard to it.

  • Step 4: Run all scripts.

enter image description here

  1. If you want to clone both structure and data do this
  • Step 1: From your destination data source create a new schema/database

enter image description here

  • Step 2: Drag and drop the current schema/database into the new schema/database which you just created

enter image description here

  • Step 3: modify something and press Import button to clone all of the tables

enter image description here

yyater97
  • 1,697
  • 2
  • 9
  • 5
  • I just tried "Option 2" to copy all tables and data and, while it creates all of the tables in the new schema, it only copies the data for the first table -- all the other tables are left empty. – walen Nov 30 '22 at 12:23