How to import a sample database to a MySQL database server using MySQL Workbench
Abstract:In this tutorial, you will learn how to use MySQL Workbench to load a MySQL sample database into a MySQL database server. Afterwards, you will have a sample database to practice and learn MySQL. classicmodels
Step 1. Download the classicmodels sample database
Step 2. Extract the downloaded file to a temporary folder. You can use any folder you want. To keep it simple, we extract it to the C:\temp
folder.
Step 3. Start the MySQL Workbench application:Program Files > MySQL > MySQL Workbench 5.2
.
Step 4. Add a new database connection, clickNew Connection,
as shown below:
Step 5. Set up a new connection: All connection parameters must be entered in this New Connection window. The following information is required:
- Connection name: The name of the connection. If you are connected to
localhost
, just typelocal
. If you are connecting to a specific host, use the hostname as the name of the connection to make it clear. - Hostname: In this case,
127.0.0.1
islocalhost
. You can enter the IP address or the name of the database server. - Username: The username you use to connect to the MySQL database. In this case, it's the
root
user.
You can also choose to provide the following information:
- Password: The password of the user used to connect to the database.
- Default mode: the database to connect to. You can leave it blank and select it later using the
use database
command.
You should click Test Connection to make sure the parameters you provide are correct and then click the OK button to create this new connection. Once completed, you will see a connection window like this:
Step 6. Click Local Database Connection to connect to the MySQL database server. Because we did not provide a password in the previous step, MySQL requires us to enter the password for theroot
account. We enter the password and click on the OK button.
If you entered your user and password correctly, you will see the following window:
Step 7. Open the SQL script by selecting File > Open SQL Script
or pressing the Ctrl+Shift+O
keyboard shortcut.
Step 8. Select the sql script file from the C drive:\temp\mysqlsampledatabase.txt
Step 9. To execute the SQL script, click the execute
button in the toolbar as shown below:
Step 10. Right-click the Schemas
panel and click the Refresh All
button to refresh the panel. Theclassimodels
database has been successfully imported to the MySQL database server.
In this tutorial, we have shown you how to load a MySQL sample database into a MySQL database server using MySQL Workbench.