FranGoitia
FranGoitia

Reputation: 1993

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.

Upvotes: 5

Views: 58669

Answers (4)

dr_
dr_

Reputation: 2292

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.

Upvotes: 6

alpha9eek
alpha9eek

Reputation: 1449

Its very easy on Linux platform just follow below mentioned steps, After downloading zip file of sakila-db, extract it. Now you will have two files, one is sakila-schema.sql and other one is sakila-data.sql.


  1. Open terminal
  2. Enter command mysql -u root -p < sakila-schema.sql
  3. Enter command mysql -u root -p < sakila-data.sql
  4. Now enter command mysql -u root -p and enter your password, now you have entered into mysql system with default database.
  5. To use sakila database, use this command use sakila;
  6. To see tables in sakila-db, use show tables command

Please take care that extracted files are present in home directory else provide the absolute path of these files in all above commands.

Upvotes: 0

Philip Olson
Philip Olson

Reputation: 4850

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

Upvotes: 19

Kumar Kailash
Kumar Kailash

Reputation: 1395

You could use mysql console from terminal. Login through the user id and pass. Then create a Database from the following command is the .sql file does not have one such command to create so.

Create database db-name
use db-name;
SOURCE xyz.sql;

Source command would load the the content from xyz.sql to your database created. This would be reflected later in workbench indeed.

Upvotes: 0

Related Questions