Help Import, export and backup

Importing CSV data

Import CSV Data Using LOAD LOCAL loads a text file of rows, such as a CSV file saved from a spreadsheet, into an existing table. bonSQL builds a LOAD DATA LOCAL INFILE statement from your choices and runs it on the current connection, so the file is read from your computer, not from the server.

The table must exist already. To make one, see Creating a table.

The Import CSV Data Using LOAD LOCAL dialog

Opening it

Select the table, or its database, in the Object Browser, then:

Tables and Columns

Tables lists the tables of the database, with the one selected in the Object Browser chosen. Columns lists its columns. Select the columns the file’s fields go into (a click selects or deselects one column); only those are named in the statement, in the order they are listed, so the file’s fields must come in that order. Select All and Deselect All help with long lists.

Delimiters

The Delimiters box shows how the file will be read: fields Terminated by, Enclosed by and Escaped by, and lines Terminated by. Unless you change them, they are \t (tab), <NONE>, \\ and \n.

Click Change… to set them in the Specify The Escape Characters window. Each setting has a tick box in front of it; untick it to leave that part out of the statement. Click OK when done.

FieldDoes
Escaped byThe character that comes before special characters inside values.
Lines terminated byWhat ends each row: \n, or \r\n for a file made on Windows.
Fixed length / Variable lengthFixed length reads fields by the columns’ widths instead of by separators.
Fields terminated byThe separator between fields, for example ,, ; or \t.
Fields enclosed byThe character around values, usually ". Tick Optionally when only some values have it.
Fill Excel Friendly ValuesSets fields separated by , and enclosed in ", escaped by \\, with lines ending \r\n.

Charset

The character set the file is written in. When you choose the file, bonSQL looks at its start: it picks ucs2 for a UTF-16 file and utf8 for UTF-8 text it recognises, and otherwise leaves the list on [default]. With [default] bonSQL adds no CHARACTER SET to the statement, so the server’s own default applies. Change it if accented letters come out wrong.

Other Options

Each option adds a word to the statement. What it does is up to the server; in short, Replace and Ignore decide what happens to a row whose key is already in the table.

OptionAdds
Low priorityLOW_PRIORITY
ConcurrentCONCURRENT. Cannot be combined with Low priority.
ReplaceREPLACE
IgnoreIGNORE. Cannot be combined with Replace.
Ignore n linesIGNORE n LINES: skips the first n lines, such as a line of column names.

Running it

Enter the file in Import from file, or click … to choose it, then click Import…. The table named in Tables receives the rows. When the server has finished, a window titled CSV Import Result shows the server’s summary of the load (how many records were read, deleted, skipped, and how many warnings there were). If there were warnings, click Show Warnings… to read them.

bonSQL remembers the file name and the options for next time.

Tips

When it does not work