Score:0

4 unicode chars appear as first few characters in file which don't seem to show in vim

us flag

vi data.sql :

-- MariaDB dump 10.19  Distrib 10.4.28-MariaDB, for Win64 (AMD64)

But when I do head -n 10 data.sql I get the first line as

��-- MariaDB dump 10.19  Distrib 10.4.28-MariaDB, for Win64 (AMD64)

As a result of which I get this while importing :

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '??-' at line 1

So how do I rectify this ?

PeterJ avatar
ru flag
Those are probably a BOM (byte order mark), I don't use MySQL so don't know if there's an option to ignore it but you could do a search on how to remove that from the SQL file.
Nikita Kipriyanov avatar
za flag
How you were generating this file? Were you editing it with e.g. Notepad (which adds BOM)?
anjanesh avatar
us flag
I used a Windows 11 version of mysqldump to dump the 1.5GB SQL and was trying to import it in a Ubuntu 22.04 server.
Score:1
ua flag

Get the hex of the beginning of the file; see https://mysql.rjweb.org/doc.php/charcoll#bom_byte_order_mark for what BOM looks like. Otherwise, check https://stackoverflow.com/questions/38363566/trouble-with-utf8-characters-what-i-see-is-not-what-i-stored for "black diamond".

If it is BOM, try to get the product that is generating it to stop, somehow remove the first 3 bytes.

Score:1
us flag

I got it solved by opening the sql file in vi and

:set fileencoding=utf-8
:wq
Score:0
us flag

it looks like a BOM or other garbage added by your editor, you can mask it in the file it using the command

echo -n --xx | dd conv=notrunc of=data.sql 

This just overwrites the bytes with an SQL comment, which Mysql (or Mariadb) will ignore.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.