1.从postgresql导出表结构,例如下面的结构
引用
--
-- PostgreSQL database dump
--

SET client_encoding = 'UTF8';
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: classes; Type: TABLE; Schema: public; Owner: jobzone; Tablespace:
--

CREATE TABLE classes (
   cid smallint NOT NULL,
   gid character(1) NOT NULL,
   cname character varying(100) NOT NULL
);


ALTER TABLE public.classes OWNER TO jobzone;

--
-- Name: pk_classes; Type: CONSTRAINT; Schema: public; Owner: jobzone; Tablespace:
--

ALTER TABLE ONLY classes
   ADD CONSTRAINT pk_classes PRIMARY KEY (gid, cid);


--
-- Name: fk_classes_reference_groups; Type: FK CONSTRAINT; Schema: public; Owner: jobzone
--

ALTER TABLE ONLY classes
   ADD CONSTRAINT fk_classes_reference_groups FOREIGN KEY (gid) REFERENCES groups(gid) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- PostgreSQL database dump complete
--

2.选择出最重要的建表语句到mysql的数据库中执行,例如将下面的内容进行执行:
引用
CREATE TABLE classes (
   cid smallint NOT NULL,
   gid character(1) NOT NULL,
   cname character varying(100) NOT NULL
);

特别注意:如果表名有双引号的,一定要去除。
3.从postgresql导出表纯数据,导出SQL格式的数据文件,例如:
引用
--
-- PostgreSQL database dump
--

SET client_encoding = 'UTF8';
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public, pg_catalog;

--
-- Data for Name: classes; Type: TABLE DATA; Schema: public; Owner: jobzone
--

INSERT INTO classes VALUES (2750, 'C', '生物制品业');
INSERT INTO classes VALUES (4183, 'C', '电子计算机修理业');
INSERT INTO classes VALUES (100, 'A', '农业');
INSERT INTO classes VALUES (2800, 'C', '化学纤维制造业');
INSERT INTO classes VALUES (4189, 'C', '其他电子设备修理业');
INSERT INTO classes VALUES (110, 'A', '种植业');
INSERT INTO classes VALUES (2810, 'C', '纤维素纤维制造业');
INSERT INTO classes VALUES (4190, 'C', '其他电子设备制造业');

4.使用vi删除sql文件中下面的内容:
引用
-- PostgreSQL database dump
--

SET client_encoding = 'UTF8';
SET check_function_bodies = false;
SET client_min_messages = warning;

SET search_path = public, pg_catalog;

--
-- Data for Name: classes; Type: TABLE DATA; Schema: public; Owner: jobzone
--

如果有必要,就是使用vi替换命令:% s/"/`/g,将"替换成`符号。
5.登录mysql,转换到你要导入的数据库,执行sql文件即可完成导入,下面例子仅作参考:
引用
#mysql -u root -p
mysql>use jobzone
mysql>\. /aaa.sql
PostgreSQL | 评论(0) | 引用(0) | 阅读(24535)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]