MySQL 导出导入二进制文件(转载)

转自:http://blog.itpub.net/16582684/viewspace-695141/

在一次从RHEL 5 dump整个数据库并在winXP下恢复,由于有一个表包含图片数据,导致“’”分隔符被吞噬(由于二进制编码的问题,引号分隔符被当作了数据的一部分),从而使得数据不能被正常导入。造成整个数据库无法导入。

解决方法:

  1. 使用select [binary_column] into dumpfile 'dump_dir' from [table_name], 然后在命令行中insert into table(binary_column) values(load_file('dump_dir')); 由于只能导出单行。用起来相当麻烦。

  2. 使用select col1, col2, ... , hex([binary_column]) into outfile 'dump_dir' from [table_name], 然后在命令行中导入load data infile 'dump_dir' into table [table_name], 最后将之前转化为十六制的字段再转为二进制 update [table_name] set [binary_column] = unhex([binary_column]),这样就完成导入过程。

注意:ERROR 1290 (HY000): The MySQL server is running with the –secure-file-priv option so it cannot execute this statement. 该错误代表dump的路径不可用,必须使用mysql默认导出目录。show variables like '%secure%';(MySQL导出数据遇到secure-file-priv问题的解决方法:https://www.jb51.net/article/125905.htm)

你可能感兴趣的:(MySQL 导出导入二进制文件(转载))