0

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 ?

anjanesh
  • 337
  • 1
  • 3
  • 11
  • 1
    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. – PeterJ Jul 29 '23 at 03:24
  • How you were generating this file? Were you editing it with e.g. Notepad (which adds BOM)? – Nikita Kipriyanov Jul 29 '23 at 17:07
  • 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. – anjanesh Jul 30 '23 at 04:52

3 Answers3

1

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.

Rick James
  • 2,463
  • 1
  • 6
  • 13
1

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

:set fileencoding=utf-8
:wq
anjanesh
  • 337
  • 1
  • 3
  • 11
0

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.

Jasen
  • 826
  • 6
  • 12