Skip to content

Instantly share code, notes, and snippets.

@bparaj
Created April 26, 2019 20:32
Show Gist options
  • Save bparaj/955a7a3e10c2711b22458658d215d4c4 to your computer and use it in GitHub Desktop.
Save bparaj/955a7a3e10c2711b22458658d215d4c4 to your computer and use it in GitHub Desktop.
Create a new mysql database in a Linux server from the mysql database dump obtained from Windows server. This need arose when I wanted to run tests on a snapshot of the production database.
1. Create a MySQL dump with `mysqldump.exe`::
mysqldump.exe --single-transaction -u user -p password -h localhost db_name > db_name_dump.sql
2. Transfer `db_name_dump.sql` to your Linux machine
3. Assume you are now in a Linux machine. `db_name_dump.sql` may not be encoded in utf-8.
$ # Find out what encoding the file has from the terminal.
$ file -i db_name_dump.sql
db_name_dump.sql: text/plain; charset=utf-16le
$ # Convert the encoding
$ iconv -f utf-16le -t utf-8 db_name_dump.sql -o db_name_dump_utf8.sql
4. Create a new mysql database that will eventually hold the contents of the dump
$ mysql -u user -p
...
> create database db_name;
> exit
5. Load data from the dump into the new mysql database
$ mysql -u root -p db_name < db_name_dump_utf8.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment