Search code examples
mysqldatabaseutf-8drupal-7

MySQL database is getting escaped wrong; cannot import it on Windows


I have a giant MySQL database (about 1.2GB, Drupal installation) that I am working with on the Mac. On the Mac, I can import it and export it between various dev servers with no trouble.

Now, I am trying to import the database into MySQL on Windows 10. When I do so, I'm getting the following errors:

C:\Users\Patrick\Sites\devdesktop\omsearch>drush @loc.om sql-cli < ../output.sql
ERROR 2005 (HY000) at line 1253: Unknown MySQL server host 'want' (0)

C:\Users\Patrick\Sites\devdesktop\omsearch>drush @loc.om sql-cli < ../20160415dd.sql
ERROR 2005 (HY000) at line 3023: Unknown MySQL server host 'animal' (0)

These words "want" and "animal" are text in a user's profile, not MySQL server hosts. So, somehow, the SQL file is not being escaped properly for import on Windows.

I am not terribly well-versed in MySQL, but I know the following from the Drupal database configuration:

  • charset: utf8mb4
  • collation: utf8mb4_general_ci

What I tried

I used Drush, the drupal command line tool, to export the database. This calls mysqldrump and I used the default options.

I then tried mysqldump --default-character-set=utf8mb4 DATABASE -r DATABASE.sql. This also gives the same error.

Example of the problem line

ifficultâ¦.Im try.I can speak Japanese.\r\n\r\nThe favorite thing is a movie and an animalâ¡','','plain_text'),('node','self_introduction',0,42898,64071,'und',0,'I would love to know people, specially 

(This may not be showing up properly because it seems VIM is also having trouble displaying the characters.)


Solution

  • The problem was not with the export but with the importing command.

    To import on Windows, I had to do this:

    mysql DATABASE --default-character-set=utf8mb4 < DATABASE.sql

    The important thing to add is the explication character set declaration: --default-character-set=utf8mb4.