Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing Data and Schema to MySQL Workbench

I'm trying to learn SQL and I downloaded a database to practice. I downloaded two files of extension .sql, one is the schema and the other one the actual data. I've also installed MySQL Workbench. I've been googling and I've been trying things to solve this but I don't understand Workbench and I can't load the database.

Where do I import the schema and the data in order to try queries ?

Any help would be really appreciated.

like image 626
FranGoitia Avatar asked Nov 29 '22 14:11

FranGoitia


2 Answers

This is simple in Workbench, and I'll use the freely available sakila database as an example. Feel free to apply this to your situation:

  1. Download "sakila" from here: http://dev.mysql.com/doc/index-other.html
  2. Extract it somewhere, in my case, onto the Desktop into a new sakila-db/ directory
  3. Open Workbench
  4. In the Schema Navigator, right-click an empty area and choose "Create Schema"
  5. In the schema creation wizard, name it "sakila", keep the defaults, hit "Apply", finish wizard
  6. Go to "File" -> "Run SQL Script..."
  7. Choose "sakila-schema.sql", make sure "Default Schema Name" is blank or select "sakila", execute
  8. Go to "File" -> "Run SQL Script..."
  9. Choose "sakila-data.sql", execute
  10. Click the "refresh" icon in the Workbench Schema Navigator (or restart Workbench)
  11. Now, use the populated sakila database :)

Steps (4) and (5) are optional in this case (as executing sakila-schema.sql creates the schema), but the idea is worth mentioning.

Here's how it would look when loading th script into the SQL IDE:

enter image description here

like image 132
Philip Olson Avatar answered Dec 10 '22 04:12

Philip Olson


The accepted answer is from 4 years ago, so I thought I'd give an update as in MySQL Workbench 6.3 the procedure is a bit different.

You have to select the menu item Server -> Data Import -> Import from Self-Contained File and select the SQL file containing the database you want to import.

In Default Target Schema, select the database you want to import the SQL dump to, or create a new empty database via New...

Then click on Start Import.

like image 27
dr_ Avatar answered Dec 10 '22 02:12

dr_