Learner0x5a's Studio.

MySQL Note

Word count: 205Reading time: 1 min
2021/09/02 Share

MySQL的迁移

导出

.\mysqldump.exe -u root -p database_name table_name > table_name.sql

.\mysqldump.exe -u root -p database_name table_name -r table_name.sql

导入

mysql -u root -p database_name < table_name.sql

场景:从windows迁移到ubuntu

一开始用powershell:

.\mysqldump.exe -u root -p database_name table_name > table_name.sql

但是在ubuntu里导入的时候报错:

ERROR: ASCII '\0' appeared in the statement, but this is not allowed unless option --binary-mode ...

查了一下发现是powershell的原因:由于写出用的是重定向,而powershell的默认编码是UTF-16,导致ubuntu导入的时候不认识
file看一下,可以发现确实如此

Little-endian UTF-16 Unicode text, with very long lines, with CRLF line terminators.

解决方案是,不采用重定向写出:

.\mysqldump.exe -u root -p database_name table_name -r table_name.sql

file的结果是:

ISO-8859 text, with very long lines或者ASCII text

然后导入:

mysql -u root -p database_name < table_name.sql

CATALOG
  1. 1. MySQL的迁移
    1. 1.1. 导出
    2. 1.2. 导入
    3. 1.3. 场景:从windows迁移到ubuntu