Importing ODS file to MySQL

Robin_ picture Robin_ · Apr 23, 2015 · Viewed 7.1k times · Source

I am trying to import an ODS file in an MySQL database with phpMyAdmin.

I clicked on the desired table (table1) on the left and clicked on the 'Import' tab.

The data in the file matchs the one of the table. I checked the option to specify that the first line of my ODS file contains the name of my columns. The format of the file is the right one.

MySQL then gives me an error : #1054 - Unknown column 'trd_id' in 'field list'

INSERT INTO `total_ws_lu`.`table2` (`trd_id`, `lng_id`, `sta_id`, `typ_id`, `civ_id`, `mkt_id`, `trd_libelle`, `trd_sort`, `loc_id`, `pay_id`, `tyt_id`) VALUES ...

The problem is that mySQL (randomly?) chose a table to import in, table2 instead of table1.

Answer

Isaac Bennetch picture Isaac Bennetch · Apr 27, 2015

When importing an ODS file like this, phpMyAdmin uses the sheet name as the table name for import; you can rename the sheet in your spreadsheet program in order to adjust to your existing table name. Another option is to import to table2 then copy (with SQL commands) to the existing table (something like

INSERT INTO table1 (`trd_id`,`lng_id`) SELECT `trd_id`, `lng_id` FROM table2

should work).

You may also have to adjust your column names in the spreadsheet to match the column names of the table; insert a row at the top of your spreadsheet and put the name of each MySQL column in the first row here, then select the checkbox for "The first line of the file contains the table column names" when importing in to phpMyAdmin.