I have a django app running on a staging server (windows server 2012) with a MariaDB database. I have a git hook running mysqldump locally when I push to the staging branch. On the server I have a batch script pulling from this branch, migrating django migrations, import the dump and finally restarting the site. Looks a bit like this:

@echo off
cd <repo>
cmd /k "git stuff && python manage.py migrate && mysql -uroot db < D:/repo/db.sql && stop/start site... && exit

Sadly though when the script reaches the dump import it spits out an error saying it doesn't know the collation (ERROR 1273 (HY000) at line 25: Unknown collation: 'utf8mb4_0900_ai_ci' ). After some googling I found out I just have to open the sql in an editor and replace all 'utf8mb4_0900_ai_ci' with 'utf8mb4_general_ci'. Sure that works for this one time, that's not entirely useful for me as this dump is part of an automated process.

Does someone know a simple solution to automate the collation replacement?

  • on linux you can make `sed -e 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' -i myfilename.sql
    – nbk
    Jul 21, 2021 at 12:36
  • I'm not on linux sadly
    – Samoht
    Jul 21, 2021 at 14:08
  • I feel your pain, but for a good while now, Microsoft is providing Linux utilities. I can't imagine sed not being part of those. Jul 21, 2021 at 14:11
  • well believe it or not.. "sed is not recognized..."
    – Samoht
    Jul 21, 2021 at 14:33
  • see if superuser.com/questions/1522245/… can help you fund a replacement, or simply don't switch databases
    – nbk
    Jul 21, 2021 at 15:03

1 Answer 1


{ Related to @nbk's suggestion (in a comment on the question) to use:
sed -e 's/utf8mb4_0900_ai_ci/utf8mb4_unicode_ci/g' -i myfilename.sql }

I think there are two main options for running Unix commands in Windows:

  1. "Windows Subsystem for Linux Documentation (WSL)" — this is provided by Microsoft. According to the "Windows interoperability with Linux" page, you should be able to run sed via the wsl.exe command, as in:

    C:\>wsl sed ...

    Please be aware that WSL2 requires Hyper-V and that might prevent VMWare and/or VirtualBox from working (if you use either or both of those). At first they didn't work with Hyper-V, then they did, then something in Windows changed and they stopped working with Hyper-V, and the current status is a little unclear (please see: WSL2 breaks VirtualBox 6.1 #798 )

  2. Many Unix/Linux commands have been ported to Windows via various 3rd party packages. The two that I am aware of are:

    • Cygwin — this project is actively maintained (most recent build is a few months ago). This is a fairly large project (currently 9907 "packages" - commands, libraries, etc), but I think you have the option to only install the components that you want. You can see the full list of packages here.
    • UnxUtils — smaller project than Cygwin, and not currently maintained (most recent update is from 2014, and on a diff site; will give link in a moment), but I believe this one is lighter weight / easier to take one or two commands as there are no dependencies. There are two sites with files to download, and it's unclear which is newer, but I think I would go to this site: http://unxutils.sourceforge.net/ and get both the UnxUtils.zip and UnxUpdates.zip files.

In both cases you can get favorites such as: sed, gawk, etc.

  • unicode gave me some insert errors, but replacing it with general did the trick. Thanks!
    – Samoht
    Jul 26, 2021 at 6:10
  • @Thomas96 You are welcome. Can you please share exactly what you did to solve this? Which solution did you go with? If you did go with sed, what was the pattern and replacement string that worked for you? Jul 26, 2021 at 6:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.