mysql을 postgresql 구문으로 변환하는 간단한 도구가 있습니까?
-
01-07-2019 - |
문제
나열된 도구를 사용해 보았습니다. 여기, 일부는 다른 것보다 더 많은 성공을 거두었지만 사용할 수 있는 유효한 postgres 구문을 제공하지 않았습니다(작은 오류 등).
해결책
거기에 mysqldump
PostgreSQL 코드를 출력하는 옵션:
mysqldump --compatible=postgresql ...
다른 팁
Google에서 잠시 후에 찾았습니다. 이 게시물.
- 설치하다 mysql2psql 보석을 사용하여
[sudo] gem install mysql2psql
. - 다음을 실행하여 구성 파일을 만듭니다.
mysql2psql
.오류가 표시되지만mysql2psql.yml
파일이 생성되어 있어야 합니다. - 편집하다
mysql2psql.yml
- 달리다
mysql2psql
다시 데이터를 마이그레이션합니다.
팁:세트 force_truncate
에게 true
당신의 mysql2psql.yml
데이터를 마이그레이션하기 전에 postgresql 데이터베이스를 지우려면 config 파일을 사용하세요.
나는 사용했다 py-mysql2pgsql.설치 후에는 yml 형식(소스, 대상)의 간단한 구성 파일만 필요합니다. 예:
# if a socket is specified we will use that
# if tcp is chosen you can use compression
mysql:
hostname: localhost
port: 3306
socket: /tmp/mysql.sock
username: mysql2psql
password:
database: mysql2psql_test
compress: false
destination:
# if file is given, output goes to file, else postgres
file:
postgres:
hostname: localhost
port: 5432
username: mysql2psql
password:
database: mysql2psql_test
용법:
> py-mysql2pgsql -h
usage: py-mysql2pgsql [-h] [-v] [-f FILE]
Tool for migrating/converting data from mysql to postgresql.
optional arguments:
-h, --help show this help message and exit
-v, --verbose Show progress of data migration.
-f FILE, --file FILE Location of configuration file (default:
mysql2pgsql.yml). If none exists at that path,
one will be created for you.
홈페이지에서 더 자세히 알아보세요 https://github.com/philipsoutham/py-mysql2pgsql.
이 postgresql 페이지에는 유료 소프트웨어가 하나 나열되어 있습니다.http://www.postgresql.org/download/products/1
그리고 이것은 pgFoundry에 있습니다:http://pgfoundry.org/projects/mysql2pgsql/
이 페이지 구문 차이점을 나열하지만 아직 작동하는 간단한 쿼리 변환기를 찾지 못했습니다.사용하기 ORM 원시 SQL 대신 패키지를 사용하면 이러한 문제를 방지할 수 있습니다.
저는 현재 레거시 코드베이스에 대한 변환기를 해킹하고 있습니다.
function mysql2pgsql($mysql){
return preg_replace("/limit (\d+), *(\d+)/i", "limit $1 offset $2", preg_replace("/as '([^']+)'/i", 'as "$1"', $mysql)); // Note: limit needs order
}
을 위한 CREATE
진술, SQL라인 대부분을 온라인으로 전환합니다.그래도 나중에 mysqldump를 편집해야 했습니다.
"mediumtext" -> "text", "^LOCK.*" -> "", "^UNLOCK.*" -> "", "`" -> '"', "'" -> "''" in 'data', "0000-00-00" -> "2000-01-01", deduplicate constraint names, " CHARACTER SET utf8 " -> " ".
"int(10)" -> "int" was missed in the last table, so pass that part of the mysqldump through http://www.sqlines.com/online again.
이것을 시도해 보세요. 정말 매력적입니다!!
http://www.sqlines.com/online
보세요 PG파운드리, Postgres에 대한 추가 유틸리티가 거기에 있는 경향이 있습니다.그래도 당신이 찾고 있는 도구가 존재한다고 믿습니다.
당신은 당신을 위해 모든 작업을 수행할 수 있는 도구를 결코 얻지 못할 것입니다.리팩토링 작업을 직접 수행할 준비를 하십시오.