07/09

As I said in last post, we got a big problem in the mysqldump double encoding bug (Bug #28969).

Now, if I just have a SQL file, which is double encoded by mysqldump, and the original database was destroyed, how can I restore the database?

The way is quite sample, but always get confusion because of the expression.

  1. Restore the SQL file into MySQL, and you will get a messy database.
  2. Use mysqldump again to export a SQL file, which is decoded.
     mysqldump -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASSWORD" \
    --opt --quote-names  --skip-set-charset \
    --default-character-set=latin1 "$DB_NAME"   > /tmp/temp.sql
  3. Restore the decoded SQL file into MySQL.

Your database now comes back!

References

正如我在上一篇日志说的那样,我们因为mysqldump(Bug #28969)的重复编码漏洞,遇到了一个大问题。

现在,加入我有一个被mysqldump重复编码的SQL文件,而原始数据库已经被摧毁,如何恢复原始数据库呢?

方法非常简单,只是它过去的表述比较容易造成误解。

  1. 恢复SQL文件到MySQL,得到充斥着乱码的数据库;
  2. 再次使用mysqldump输出一个解码的SQL文件;
     mysqldump -h "$DB_HOST" -u "$DB_USER" -p"$DB_PASSWORD" \
    --opt --quote-names  --skip-set-charset \
    --default-character-set=latin1 "$DB_NAME"   > /tmp/temp.sql
  3. 恢复这个新的SQL文件到MySQL中。

你的数据库现在回来了!

参考文献