- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我想将一些表从 Postgres 数据库转换到 MySQL。理想情况下,我想创建一个脚本,将 PG 的表转换为 MySQL,但如果我们能够弄清楚如何以一种不可编写脚本的方式实现这一点,我会很高兴。
首先,我在这里读过一篇类似的帖子:Migrate database from Postgres to MySQL
我已经尝试了那里提出的两种解决方案,但它们都没有成功。
重要的是说我想迁移结构和数据。
但首先,这里是 postgres 数据库的 SQL 转储:
--
-- PostgreSQL database dump
--
SET statement_timeout = 0; SET client_encoding = 'UTF8'; SET standard_conforming_strings = off; SET check_function_bodies = false; SET client_min_messages = warning; SET escape_string_warning = off;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = false;
--
-- Name: grupos; Type: TABLE; Schema: public; Owner: postgres; Tablespace:
--
CREATE TABLE grupos (
"dirGrupo" text,
valor real,
"flagIntelli" boolean DEFAULT false,
"flagQDS" boolean DEFAULT false,
finalidad text,
"idGrupo" integer DEFAULT nextval('"idGrupo"'::regclass) NOT NULL,
"claseDomo" text,
instalado boolean DEFAULT true NOT NULL,
"codCasa" "char",
"codUnidad" integer,
protocolo text NOT NULL,
escritura boolean,
dispositivo text,
"tipoDatos" oid,
"coordX" integer DEFAULT (-1),
"coordY" integer DEFAULT (-1),
mapa text,
"reglasAsociadas" text );
ALTER TABLE public.grupos OWNER TO postgres;
--
-- Data for Name: grupos; Type: TABLE DATA; Schema: public; Owner: postgres
--
INSERT INTO grupos VALUES (NULL, 0, false, false, 'sensor', 10, 'LightSensor', true, 'E', 1, 'x10', false, 'SensorLum1', 7, -1, -1, NULL, NULL); INSERT INTO grupos VALUES (NULL, 0, false, false, 'luz', 11, 'SimpleLamp', true, 'K', 1, 'x10', true, 'Luz4', 1, -1, -1, NULL, NULL); INSERT INTO grupos VALUES (NULL, 0, false, false, 'Radiador de la sala', 298, 'Heater', true, 'B', 1, 'x10', true, 'RadiadorX10', 1, 163, 168, 'Sala Quercus', '108;111;115;117;119;123;127;131;134;136;138;140;144;148;150;152;155;157;159;162;166;169;172;176;179;182;185;188;190;193;196;199;201;205;209;214;218;222;226;230;234;238;250;254;260;264;277;278;279;280;284;293;297;301;305;309;313;315;315;315;315;315;315;315;315;315;315;315;315;315;315;315;315;'); INSERT INTO grupos VALUES ('0/0/5', 1, false, false, 'Interruptor', 213, 'Button', true, NULL, NULL, 'knx', true, 'Interruptor', 1, 301, 326, 'Plano Casa', NULL); INSERT INTO grupos VALUES ('0/0/4', 0, false, false, 'Enchufe4', 316, 'Switch', true, NULL, NULL, 'knx', true, 'Enchufe4', 1, 303, 133, 'Plano Casa', '268;272;276;'); INSERT INTO grupos VALUES ('0/0/2', 0, false, false, 'Enchufe2', 210, 'Switch', true, NULL, NULL, 'knx', true, 'Enchufe2', 1, 141, 322, 'Plano Casa', NULL); INSERT INTO grupos VALUES ('0/0/1', 0, false, false, 'LuzFlexo', 217, 'SimpleLamp', true, NULL, NULL, 'knx', true, 'LuzFlexo', 1, 80, 45, 'Plano Casa', '267;271;275;'); INSERT INTO grupos VALUES ('0/0/3', 1, false, false, 'Router', 221, 'Router', true, NULL, NULL, 'knx', true, 'Router1', 1, 467, 439, 'Plano Casa', NULL); INSERT INTO grupos VALUES ('0/0/6', 21.68, false, false, 'SensorTemperatura', 237, 'TemperatureSensor', true, NULL, NULL, 'knx', false, 'SensorTemperatura', 2, 146, 436, 'Plano Casa', NULL); INSERT INTO grupos VALUES (NULL, 0, false, false, 'SensorX10', 219, 'MotionSensor', true, 'A', 1, 'x10', false, 'SensorX10', 6, 362, 11, 'Plano Casa', '335;336;'); INSERT INTO grupos VALUES ('1/1/5', 1, false, false, '', 12, 'MotionSensor', true, NULL, NULL, 'knx', false, 'SensorPresencia', 6, -1, -1, NULL, NULL); INSERT INTO grupos VALUES ('1/1/2', 50, false, true, 'Luz Intervalo', 248, 'DimmableLight', true, NULL, NULL, 'knx', true, 'LuzHInt', 3, 97, 276, 'Plano Casa', '265;269;273;338;'); INSERT INTO grupos VALUES ('1/1/1', 0, false, false, 'LuzHBin', 215, 'SimpleLamp', true, NULL, NULL, 'knx', true, 'LuzHBin', 1, 357, 189, 'Plano Casa', '266;270;274;'); INSERT INTO grupos VALUES (NULL, 1, false, true, 'Encender la luz del flexo', 291, 'SimpleLamp', true, 'C', 1, 'x10', true, 'BombillaX10', 1, 272, 130, 'Sala Quercus', '107;109;110;112;113;114;116;118;120;121;122;124;125;126;128;129;130;132;133;135;137;139;141;142;143;145;146;147;149;151;153;154;156;158;160;161;163;164;165;167;168;170;171;173;174;175;177;178;180;181;183;184;186;187;189;191;192;194;195;197;198;200;202;203;204;206;207;208;210;211;212;213;215;216;217;219;220;221;223;224;225;227;228;229;231;232;233;235;236;237;239;240;249;251;252;253;255;256;257;258;259;261;262;263;281;282;283;290;291;292;294;295;296;298;299;300;302;303;304;306;307;308;310;311;312;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;335;336;');
--
-- Name: grupos_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres; Tablespace:
--
ALTER TABLE ONLY grupos
ADD CONSTRAINT grupos_pkey PRIMARY KEY ("idGrupo");
--
-- Name: grupos_tipoDatos_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY grupos
ADD CONSTRAINT "grupos_tipoDatos_fkey" FOREIGN KEY ("tipoDatos") REFERENCES "TiposDatos"(id);
--
-- PostgreSQL database dump complete
--
1) 第一种方法,使用 pG2Mysql:http://www.lightbox.ca/pg2mysql.php简单快速(理论上):不幸的是它在解析时有几个错误:
这是检索到的文档:
# Converted with pg2mysql-1.9
# Converted on Mon, 22 Apr 2013 14:12:28 -0400
# Lightbox Technologies Inc. http://www.lightbox.ca
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone="+00:00";
CREATE TABLE grupos (
`dirGrupo` text,
valor real,
`flagIntelli` bool DEFAULT 0,
`flagQDS` bool DEFAULT 0,
finalidad text,
`idGrupo` int(11) auto_increment NOT NULL,
`claseDomo` text,
instalado bool DEFAULT 1 NOT NULL,
`codCasa` `char`,
`codUnidad` int(11),
protocolo text NOT NULL,
escritura bool,
dispositivo text,
`tipoDatos` oid,
`coordX` int(11) DEFAULT -1 ,
`coordY` int(11) DEFAULT -1 ,
mapa text,
`reglasAsociadas` text , PRIMARY KEY(`idGrupo`) ) TYPE=MyISAM;
INSERT INTO grupos VALUES (NULL, 0, false, false, 'sensor', 10, 'LightSensor', true, 'E', 1, 'x10', false, 'SensorLum1', 7, -1, -1, NULL, NULL); INSERT INTO grupos VALUES (NULL, 0, false, false, 'luz', 11, 'SimpleLamp', true, 'K', 1, 'x10', true, 'Luz4', 1, -1, -1, NULL, NULL); INSERT INTO grupos VALUES (NULL, 0, false, false, 'Radiador de la sala', 298, 'Heater', true, 'B', 1, 'x10', true, 'RadiadorX10', 1, 163, 168, 'Sala Quercus', '108;111;115;117;119;123;127;131;134;136;138;140;144;148;150;152;155;157;159;162;166;169;172;176;179;182;185;188;190;193;196;199;201;205;209;214;218;222;226;230;234;238;250;254;260;264;277;278;279;280;284;293;297;301;305;309;313;315;315;315;315;315;315;315;315;315;315;315;315;315;315;315;315;'); INSERT INTO grupos VALUES ('0/0/5', 1, false, false, 'Interruptor', 213, 'Button', true, NULL, NULL, 'knx', true, 'Interruptor', 1, 301, 326, 'Plano Casa', NULL); INSERT INTO grupos VALUES ('0/0/4', 0, false, false, 'Enchufe4', 316, 'Switch', true, NULL, NULL, 'knx', true, 'Enchufe4', 1, 303, 133, 'Plano Casa', '268;272;276;'); INSERT INTO grupos VALUES ('0/0/2', 0, false, false, 'Enchufe2', 210, 'Switch', true, NULL, NULL, 'knx', true, 'Enchufe2', 1, 141, 322, 'Plano Casa', NULL); INSERT INTO grupos VALUES ('0/0/1', 0, false, false, 'LuzFlexo', 217, 'SimpleLamp', true, NULL, NULL, 'knx', true, 'LuzFlexo', 1, 80, 45, 'Plano Casa', '267;271;275;'); INSERT INTO grupos VALUES ('0/0/3', 1, false, false, 'Router', 221, 'Router', true, NULL, NULL, 'knx', true, 'Router1', 1, 467, 439, 'Plano Casa', NULL); INSERT INTO grupos VALUES ('0/0/6', 21.68, false, false, 'SensorTemperatura', 237, 'TemperatureSensor', true, NULL, NULL, 'knx', false, 'SensorTemperatura', 2, 146, 436, 'Plano Casa', NULL); INSERT INTO grupos VALUES (NULL, 0, false, false, 'SensorX10', 219, 'MotionSensor', true, 'A', 1, 'x10', false, 'SensorX10', 6, 362, 11, 'Plano Casa', '335;336;'); INSERT INTO grupos VALUES ('1/1/5', 1, false, false, '', 12, 'MotionSensor', true, NULL, NULL, 'knx', false, 'SensorPresencia', 6, -1, -1, NULL, NULL); INSERT INTO grupos VALUES ('1/1/2', 50, false, true, 'Luz Intervalo', 248, 'DimmableLight', true, NULL, NULL, 'knx', true, 'LuzHInt', 3, 97, 276, 'Plano Casa', '265;269;273;338;'); INSERT INTO grupos VALUES ('1/1/1', 0, false, false, 'LuzHBin', 215, 'SimpleLamp', true, NULL, NULL, 'knx', true, 'LuzHBin', 1, 357, 189, 'Plano Casa', '266;270;274;'); INSERT INTO grupos VALUES (NULL, 1, false, true, 'Encender la luz del flexo', 291, 'SimpleLamp', true, 'C', 1, 'x10', true, 'BombillaX10', 1, 272, 130, 'Sala Quercus', '107;109;110;112;113;114;116;118;120;121;122;124;125;126;128;129;130;132;133;135;137;139;141;142;143;145;146;147;149;151;153;154;156;158;160;161;163;164;165;167;168;170;171;173;174;175;177;178;180;181;183;184;186;187;189;191;192;194;195;197;198;200;202;203;204;206;207;208;210;211;212;213;215;216;217;219;220;221;223;224;225;227;228;229;231;232;233;235;236;237;239;240;249;251;252;253;255;256;257;258;259;261;262;263;281;282;283;290;291;292;294;295;296;298;299;300;302;303;304;306;307;308;310;311;312;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;314;316;317;335;336;'); ALTER TABLE grupos
ADD CONSTRAINT grupos_pkey PRIMARY KEY ("idGrupo");
当我使用任何数据库管理器将此文件导入数据库时,我只收到错误消息:
出于某种原因,解析器在这些符号之间标记字符:''。如果我们仔细观察,有时列的名称在 '' 之间,有时则不是,这是为什么?
我删除了 char 周围的那些符号并继续再次执行相同的导入,但再次出现另一个错误:
类型 oid?那是什么?阅读我看到这是一种用于主键的类型。
2) 第二种方法,我会尝试使用 Mysql Workbench :
我在 Ubuntu 中安装了这个功能并试了一下。有一个迁移数据库的选项,太棒了!
1.- 我介绍来源并测试连接:
2.- 然后是 Destination 并测试连接:
3.- 下一个屏幕,一切正常:
4.- 现在要求我选择架构,我选择默认选项:
5.- 我收到以下错误,在名为“逆向工程选择的模式”的点失败。
Starting...
Connect to source DBMS...
- Connecting...
Connecting to postgresql@DRIVER=Postgresql;SERVER=158.49.245.68;PORT=5432...
Opening ODBC connection to DRIVER=Postgresql;SERVER=158.49.245.68;PORT=5432;DATABASE=QDSDatabase;UID=postgres...
Connected
Connect to source DBMS done
Reverse engineer selected schemata....
Reverse engineering public from QDSDatabase
- Reverse engineering catalog information
Traceback (most recent call last):
File "/usr/lib/mysql-workbench/modules/db_postgresql_re_grt.py", line 335, in reverseEngineer
return PostgresqlReverseEngineering.reverseEngineer(connection, catalog_name, schemata_list, context)
File "/usr/lib/mysql-workbench/modules/db_generic_re_grt.py", line 207, in reverseEngineer
catalog = cls.reverseEngineerCatalog(connection, catalog_name)
File "/usr/lib/mysql-workbench/modules/db_generic_re_grt.py", line 367, in reverseEngineerCatalog
cls.reverseEngineerSequences(connection, schema)
File "/usr/lib/mysql-workbench/modules/db_postgresql_re_grt.py", line 76, in reverseEngineerSequences
min_value, max_value, start_value, increment_by, last_value, is_cycled, ncache = cls.execute_query(connection, seq_details_query % (schema.name, seq_name)).fetchone()
File "/usr/lib/mysql-workbench/modules/db_generic_re_grt.py", line 56, in execute_query
return cls.get_connection(connection_object).cursor().execute(query, *args, **kwargs)
pyodbc.ProgrammingError: ('42P01', '[42P01] ERROR: no existe la relaci\xc3\xb3n \xc2\xabpublic.idtipodatos\xc2\xbb;\nError while executing the query (7) (SQLExecDirectW)')
Traceback (most recent call last):
File "/usr/share/mysql-workbench/libraries/workbench/wizard_progress_page_widget.py", line 192, in thread_work
self.func()
File "/usr/lib/mysql-workbench/modules/migration_schema_selection.py", line 160, in task_reveng
self.main.plan.migrationSource.reverseEngineer()
File "/usr/lib/mysql-workbench/modules/migration.py", line 332, in reverseEngineer
self.state.sourceCatalog = self._rev_eng_module.reverseEngineer(self.connection, self.selectedCatalogName, self.selectedSchemataNames, self.state.applicationData)
SystemError: ProgrammingError("('42P01', '[42P01] ERROR: no existe la relaci\xc3\xb3n \xc2\xabpublic.idtipodatos\xc2\xbb;\nError while executing the query (7) (SQLExecDirectW)')"): error calling Python module function DbPostgresqlRE.reverseEngineer
ERROR: Reverse engineer selected schemata: ProgrammingError("('42P01', '[42P01] ERROR: no existe la relaci\xc3\xb3n \xc2\xabpublic.idtipodatos\xc2\xbb;\nError while executing the query (7) (SQLExecDirectW)')"): error calling Python module function DbPostgresqlRE.reverseEngineer
Failed
6.- 如果我尝试使用其他类型的模式(要点 4.-),程序会突然关闭:
就是这样,我已经用 Mysql Workbench 尝试了几种方法,这看起来很棒,但不幸的是没有任何效果。
有什么想法吗?请记住,postgres SQL 位于帖子的开头,因此任何人都可以尝试迁移。
最佳答案
恐怕这对你来说很难。
如果这是您的整个架构,只需将其复制到您选择的文本编辑器中并手动更新即可。
“oid”列的用途我不能说,但它与主键无关(可能是大对象或“blob”?)。
仅在您使用混合大小写标识 LikeThis 时才使用引号。默认情况下,SQL 不区分大小写。
Mysql 没有真正的“ bool ”类型,您可能需要使用 bit
或 tinyint
。
架构中的 nextval() 调用是为了生成唯一的 ID。这是一个 PostgreSQL 的东西,在 MySQL 中不受支持——你可能需要一个 auto_increment 修饰符。
在这些提示和 pg2mysql 输出之间应该可以帮助您入门。
关于mysql - 如何将数据库从 Postgres 迁移到 MySQL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16189784/
我想知道这里是否有人有安装 Postgres-XL 的经验,新的开源多线程版本的 PostgreSQL。我计划将一组 1-2 TB 的数据库从常规 Postgres 9.3 迁移到 XL,并且想知道这
我想创建一个 postgres 备份脚本,但我不想使用 postgres 用户,因为我所在的 unix 系统几乎没有限制。我想要做的是在 crontab 上以 unix 系统(网络)的普通用户身份运行
我正在尝试编写一个 node-postgres 查询,它采用一个整数作为参数在间隔中使用: const query = { text: `SELECT foo
如何在不使用 gui 的情况下停止特定的 Postgres.app 集群。 我想使用 bash/Terminal.app 而不是 gui 我还应该指出,Postgres 应用程序有一个这样的菜单 如果
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
我正在使用 docker 运行 Postgres 图像。它曾经在 Windows10 和 Ubuntu 18.04 上运行没有任何问题。 在 Ubuntu 系统上重新克隆项目后,它在运行 docker
我正在使用 python(比如表 A)将批处理 csv 文件加载到 postgres。我正在使用 pandas 将数据上传到更快的 block 中。 for chunk in pd.read_csv(
所以是的,标题说明了一切,我需要以某种方式将 DB 从源服务器获取到新服务器,但更重要的是旧服务器正在崩溃 :P 有什么方法可以将它全部移动到新服务器并导入它? 旧服务器只是拒绝再运行 Postgre
这主要是出于好奇而提出的问题。我正在浏览 Postgres systemd 单元文件,以了解 systemd 可以做什么。 Postgres 有两个 systemd 单元文件。一个用于代替 syste
从我在 pg_hba.conf 中读到的内容,我推断,为了确保提示我输入 postgres 用户的密码,我应该从当前的“对等”编辑 pg_hba.conf 的前两个条目的方法'到'密码'或'md5',
我已连接到架构 apm。 尝试执行函数并出现以下错误: ERROR: user mapping not found for "postgres" 数据库连接信息说: apm on postgres@
我在 ubuntu 12.04 服务器上,我正在尝试安装 postgresql。截至目前,我已成功安装它但无法配置它。我需要创建一个角色才能继续前进,我在终端中运行了这个命令: root@hostna
我无法以“postgres”用户身份登录到“postgres”数据库。操作系统:REHL 服务器版本 6.3PostgreSQL 版本:8.4有一个数据库“jiradb”用作 JIRA 6.0.8 的
我正在尝试将现有数据库导入 postgres docker 容器。 这就是我的处理方式: docker run --name pg-docker -e POSTGRES_PASSWORD=*****
我们的 Web 应用程序在 postgres 9.3 和 Grails 2.5.3 上运行。当我们重新启动 postgres (/etc/init.d/postgresql restart) 并访问网
我想构建 postgres docker 容器来测试一些问题。我有: postgres 文件的归档文件夹(/var/lib/postgres/data/) 将文件夹放入 docker postgres
我有一个名为“stuff”的表,其中有一个名为“tags”的 json 列,用于存储标签列表,还有一个名为“id”的列,它是表中每一行的主键。我正在使用 postgres 数据库。例如,一行看起来像这
我对 sqlalchemy-psql 中的锁定机制是如何工作的感到非常困惑。我正在运行一个带有 sqlalchemy 和 postgres 的 python-flask 应用程序。由于我有多个线程处理
我(必须)使用 Postgres 8.4 数据库。在这个数据库中,我创建了一个函数: CREATE OR REPLACE FUNCTION counter (mindate timestamptz,m
我已经使用 PostgreSQL 几天了,它运行良好。我一直在通过默认的 postgres 数据库用户和另一个具有权限的用户使用它。 今天中午(在一切正常之后)它停止工作,我再也无法回到数据库中。我会
我是一名优秀的程序员,十分优秀!