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