Professional Documents
Culture Documents
1 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Featured Tutorials: SQL JOINS, Introduction to DOM, Jquery, HTML5 Canvas Tutorial, Bootstrap 3.0.0, PHP
Exercises, JavaScript Exercises
Advertise Here
Exporting and importing data between MySQL and Microsoft excel has
average rating 7 out of 10. Total 93 users rated.
<<Previous
Next>>
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
2 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
You can install the MySQL For Excel component while installing MySQL
Community Server 6. Or you may install it as an add on upon your existing
MySQL Server installation. Installation of this component has some prerequisites
though.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
3 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Step 2 :
Click on Data Tab, see the above picture, the" MySQL for Excel" Database icon
will appear shown below.
Step 3 :
Click on "MySQL for Excel" Database icon. It opens a new Excel sidebar with the
available MySQL for Excel options. The navigation bar with the MySQL for Excel
icon is shown in the following picture.:
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
4 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Here our Database is employee and we are working with location table, but the
screen will look the same for any table.
Step 4 :
Within MySQL for Excel sidebar open a MySQL connection by double clicking.
Here our connection is Local instance MySQL5.6 and with following screen will
appear for accepting the password.
Step 5 :
Enter password for connection with MySQL server. The databases will show in
MySQL for Excel sidebar. Our Database is employee. See the following picture.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
5 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Step 6 :
Double click on your desire database, and the tables within the database will
display. Our table is location. See the following picture.
Step 7 :
Select the table which you want to edit, click "Edit MySQL Data" inside the
navigation bar as shown above, and see the following screen shot.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
6 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Step 8 :
Click on Import button as mention in the above picture, and watch the following
screen shot. The data of the selected table will appear and if you place the cursor
within the data range the Revert Data and Commit Changes button ( specified by
a red color rectangle ) will appear other wise not.
Step 9 :
Here in our table the first column ID is a primary key. If we change the value of ID
in A19 cell 17 instead of 18 and press enter key the color of this cell will be green.
Now we have changed the value of F16 cell is London and press enter key the
cell color will change in to green, and the color yellow at the last, indicate that the
cells that accept new data. Data entered here is inserted into the MySQL table.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
7 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Step 10 :
Now if we click the Revert Data button, watch the following screen shot.
Here in above picture if you click the Refresh Data from DB the data will be refresh and
display the original data from DB, and if you click on Revert Changed Data, you will
loose your changes just made. In this stage if you click on Commit Changes button look
the following screen shot.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
8 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Here in the above picture you are looking an error message, and the color of A19
cell changed from green to red, that is because the ID column is primary key and
the uniqueness have been violated here. Now we returned the value of A19 cell in
its original value, i.e. 18, and click on Commit Changes button, and now look the
below screen shot.
In the above picture shows the color of cell F16 have converted from green to
blue, that means Commit Changes done successfully. Now you can close the
Excel window saving or not but the database table have been updated. You can
see it to do the step again. If you checked the Auto Commit check box, effect
immediately be seen in your sheet and data will be updated in MySQL database.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
9 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Importing Table
Include Column Names as Headers: By default this option is enabled, and this
treats the column names at the top of the Microsoft Excel spreadsheet as a
"headers" row and will be insert as a header.
Limit to and Rows and Start with Row : By default this option is disabled , if
enabled, this limits the range of imported data. The Limit to option defaults to 1,
and this limit can be changed by defines the number of rows to import. The Start
with Row option defaults to 1, i.e. starting from first row, and it can be changed by
defines the number from where the import begins. Each option has a maximum
value of COUNT(rows) in the table.
Now assumed that we want to import the columns LOATION_ID and CITY. Click
the mouse on LOCATION_ID column and then press and hold CTRL key and
click on CITY column, and look the following screen shot.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
10 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Now if we click the Import button all the rows for this two columns will be import in
Microsoft Excel Worksheet.
Assumes that, we want to import only 6 rows beginning from 3rd row. Now look
the following screen shot.
Here in the above picture shows all the columns have selected and the value of
Limit to is 6, that means number of 6 rows will be imported and the beginning of
importing will be start from 3rd row, because we have set the value of Start with
Row is 3. Now click the Import button and look the following screen shot.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
11 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Column mappings
Mapping the Excel columns to the MySQL columns can be executed
automatically (default), manually, or by using a stored mapping routine. To append
the data from Excel to MySQL the following step to be followed:
At first do the above 6 steps of "Edit MySQL Data in Excel" then input records in
excel spreadsheet compatible to the structure of MySQL table in which you want
to append the records. Here is the example in which we have taken only one row,
you may take more than one rows and then select the records. See the following
screen shot.
Now click on the Append Excel Data to Table as mention above, and look the
screen like.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
12 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Here in the above picture you are looking two colors for the legend. One is Red
and another is Green.
The Green color indicate that a source column is mapped ( mapped means the
source columns in above grid created in the spreadsheet have been matched with
structure of the MySQL table as target columns shown in below grid ) to a target
column and here in the above picture shows all the source columns have been
mapped with target columns.
If you drag any target column heading backed by green color and leave it in
outside the grid, the color of the target column will be Red and the color of the
source column will be Gray. See in below picture.
Here in the above picture the target column4 became Red and source column4
became Gray.
The Red color indicate that a target column is not mapped and the Gray color
indicate that, a source column is not mapped.
It is to be noted that, a source column may be mapped to multiple target columns,
although this action generates a warning dialog and right-clicking on a target
column shows a menu with options to either Remove Column Mapping for a
single column, or to Clear All Mappings for all columns.
Suppose, we are mapping manually by dragging source column4 with target
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
13 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
column4 and column5. The target column4 will be mapping simply but when doing
the process for target column5 the warning dialog will appear, show below.
Mapping methods
Here look the three mapping methods:
The automatic mapping method attempts to match the Excel source column
names with the MySQL target table column names.
In the manual mapping method source column names are manually dragged
with the target column names. After the Automatic method is selected the Manual
dragging method can also be performed.
You may store your own mapping styles using the Store Mapping button and
saved a name like "name (dbname.tablename)" and it will be available in the
Mapping Method combo box.
Stored mappings may be deleted or renamed within the Advanced
Options dialog.
Advanced Options
If we click the Advanced Options button the dialog looks similar to:
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
14 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
15 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Now click on Export Excel Data to New Table mention by arrow in the above
picture and look the following screen.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
16 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
1 - Specify a unique name for the MySQL table. Suppose the name of the MySQL
table is "invoice"
2 - If Add a Primary Key column radio button is checked an additional primary
key column will be add, you can change the name of the column and by default
the data type will be integer which is displaying in 7.
3 - When you check the Use Existing Columns radio button the column names will
the available in the combo box and you can choose the primary key column from
the list, and the column will be selected. Suppose you selected INVOICE_NO
column, look the following picture.
Here in the above picture the INVOICE_NO column have been selected and now
you can change the Column Name (point 6), Data type (point 7) and the
constraint (point 9) which are active.
4 - If you check the check box First Row Contains Column Names (point 4) the
first column in your excel data will be heading other wise it will be
column1,column2,... etc
5 - Suppose you change the Data type and column name for other columns you
can click on the column heading. Assumed that we want to change the Data type
of INVOICE_DT, click on INVOICE_DT, and this column will be selected and then
you can use point 6,7 and 9.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
17 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
Advanced Options
Use the first 100 (default) Excel data rows to preview and calculate data
types: This option determines the number of rows that the preview displays, and
the specified values affect the feature of automatic mapping.
Analyze and try to detect correct data type based on column field contents:
This option try to analyze the data and determine the data type for the column.
When the column contains multiple types of data then it defined as VARCHAR.
Add additional buffer to VARCHAR length (round up to 12, 25, 45, 125, 255):
When it is enabled, it detects the data type automatically and set to VARCHAR,
then it find the maximum length for all rows within the column, and rounds it up
the maximum length to one of the defined lengths above and when disabled, then
the VARCHAR length is set to the length of the longest entry in the Excel
spreadsheet.
Automatically check the Index checkbox for Integer columns: By default this
option is enabled , and then columns with an Integer data type will have the
Create Index option enabled by default.
Automatically check the Allow Empty checkbox for columns without an
index: By default this option is enabled, and when enabled the columns without
the Create Index checkbox checked will automatically enable the Allow Empty
configuration option.
Use formatted values: By default this option is enabled, and the data from Excel
is treated as Text, Double, or Date but when disabled the data's are independent,
that is they have no specific data type.
Remove columns that contain no data, otherwise flag them as "Excluded":
When this option is enabled, columns without data in Excel are removed and not
shown in the preview panel. By default this option is disabled and then these
columns will exist but have the Exclude Column option checked.
After completion all setting click Export button the and see the following screen
shot -
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
18 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
<<Previous
Next>>
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
19 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
2 Comments
Alan Lilly
sunil
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
19/04/2014 2:57
Exporting and importing data between MySQL and Microsoft excel - w3...
20 of 20
http://www.w3resource.com/mysql/exporting-and-importing-data-betwe...
19/04/2014 2:57