Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import excel file into MySQL Workbench?

I've googled this but all the examples are on an old excel. My current excel does not have the option of MySQL on the Data tab. i tried importing through Other Source, SQL Server but it doesn't connect through Server name. I don't understand why or if i'm putting in the wrong Server name. Should it be something other than localhost?

like image 728
Piper Ramirez Avatar asked Oct 25 '18 12:10

Piper Ramirez


2 Answers

You cannot import an excel file in MySQL Workbench. That was never possible as it would require to parse the excel file. Instead export your excel file in Excel to CSV and import that in MySQL Workbench.

Importing CSV into MySQL via MySQL Workbench is easy. Open the Table Data Import Wizard from the schema tree:

enter image description here

It allows you to import CSV and JSON data. Select your file on the next page, set import options too (e.g. separator and quote char) and then let it run.

like image 99
Mike Lischke Avatar answered Oct 20 '22 04:10

Mike Lischke


You can copy paste your Excel data in the result grid of Mysql Workbench.

Simply select in your Excel sheet all the rows and columns you want to insert in your database and copy them.

enter image description here

Copying cells containing formulas works, but pay attention to:

  • disable the thousand separator for numbers;
  • change the decimal separator to be a dot for numbers;
  • avoid empty cells as they trigger an error that the column number does not match.

After having copied the cells, right-click in Mysql Workbench on your table and choose "Select Rows" and the results of your query will appear in a result grid.

enter image description here

Right-click in the result grid in the empty row at the bottom and choose "Paste Row" from the menu.

enter image description here

Then click on "Apply" and confirm the insert queries. If everything goes well, your data will be inserted. Otherwise MySQL errors (constraint violations, etc.) are displayed. These errors can help you debugging what went wrong and where you need to correct your Excel data.

For me this works well and I didn't encounter any encoding issues yet.

However there are performance issues if you want to paste large datasets.

like image 24
Christophe Weis Avatar answered Oct 20 '22 05:10

Christophe Weis