将mysql二进制转换为postgresql bytea [英] Convert mysql binary to postgresql bytea
问题描述
从mysql导出数据并将其导入postgresql的最简单方法是什么?
我在MySQL二进制字段转换方面遇到麻烦.
MySQL中 binary
类型的等效项是PostgreSQL中的 bytea
.
您可以使用 pgloader (最简单的方法)
安装pgloader后,创建简单的脚本 test.load
加载数据库来自mysql://username:password @ host/database_name到postgresql://postgres:postgres @ localhost/database_nameWITH include drop,创建表,创建索引,重置序列将maintenance_work_mem设置为"128MB",work_mem为"12MB"使用字节向量到字节的CAST类型二进制TO bytea drop typemod;
在您的终端中运行它:
pgloader test.load
另一种方法是使用 mysqldump
1.使用十六进制选项转储它
mysqldump -u用户名-p -h主机--skip-quote-names --hex-blob --skip-triggers \--compact --no-create-info your_db your_table>前倾转储
2.进行sed操作,以便可以将其插入 bytea
类型列
sed"s/0x \([0-9A-F] * \)/decode('\ 1','hex')/g" prepg.dump>pg.dump
3.加载到您的PostgreSQL表中
\ i'/path_to_file/pg.dump'
参考 >
What is the easiest way to export data from mysql and import it in postgresql?
I am having trouble with the MySQL binary fields conversion.
The equivalent of binary
type in MySQL is bytea
in PostgreSQL.
You can use pgloader (simplest way)
After installing pgloader, create simple script test.load
load database
from mysql://username:password@host/database_name
into postgresql://postgres:postgres@localhost/database_name
WITH include drop, create tables, create indexes, reset sequences
SET maintenance_work_mem to '128MB',
work_mem to '12MB'
CAST type binary TO bytea drop typemod using byte-vector-to-bytea;
Run it in your terminal:
pgloader test.load
Another way is using mysqldump
1. Dump it with hex-blob option
mysqldump -u username -p -h host --skip-quote-names --hex-blob --skip-triggers \
--compact --no-create-info your_db your_table > prepg.dump
2. Do sed so it can be inserted to you bytea
type column
sed "s/0x\([0-9A-F]*\)/decode('\1','hex')/g" prepg.dump > pg.dump
3. Load into your PostgreSQL table
\i '/path_to_file/pg.dump'
这篇关于将mysql二进制转换为postgresql bytea的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!