PostgreSQL导出一张表到MySQL
1. 查看PostgreSQL表结构,数据量,是否有特殊字段值
region_il=# select count(*) from result_basic;
count
---------
2611527
(1 row)
region_il=# \d result_basic
Table "noco_il_16q1.result_basic"
Column | Type | Modifiers
-----------------------+-----------------------+-----------
result_id | integer | not null
ppid | character varying(24) |
title | character varying |
categories | integer[] |
phone | character varying(24) |
brand_code | character varying(24) |
street_address | character varying |
zip_code | character varying(24) |
city | character varying |
state | character varying(50) |
country | character varying(50) |
lat | double precision |
lon | double precision |
vendor_code | character varying(24) |
vendor_poi_id | character varying(32) |
actual_street_address | character varying |
actual_zip_code | character varying(24) |
extender | json |
titles | json |
Indexes:
"result_basic_pkey" PRIMARY KEY, btree (result_id)
"result_basic_vendor_poi_id_idx" btree (vendor_poi_id)
region_il=# \x
Expanded display is on.
region_il=# select * from result_basic where result_id = 2;
-[ RECORD 1 ]---------+---------------------------------------------
result_id | 2
ppid | SUK5QD9B7C16D826B26E5
title | هندسة العمارة والديكور
categories | {791}
phone |
brand_code |
street_address | طريق الأمير مقرن بن عبدالعزيز
zip_code | 42314
city | المدينة
state | المدينة
country | SAU
lat | 24.47893
lon | 39.65331
vendor_code | NOCO
vendor_poi_id | 1040248605
actual_street_address |
actual_zip_code |
extender | {"sideOfStreet":"+","mapLinkId":"571732670"}
titles |
2. 导出PostgreSQL表结构
$ pg_dump --verbose --schema-only --table=noco_il_16q1.result_basic region_il -f /usr/local/pgsql/dba/exp/result_basic_schema.sql
3. 导出PostgreSQL表的所有字段
region_il=# COPY result_basic TO '/usr/local/pgsql/dba/exp/result_basic.csv' WITH (DELIMITER '^',FORMAT csv,FORCE_QUOTE *);
COPY 2611527
4. 将备份集传到MySQL数据库服务器
$ scp /usr/local/pgsql/dba/exp/result_basic* root@172.16.101.66:/usr/local/mysql/dba/imp/
5. 编辑表结构文件修改字段类型并创建MySQl表结构
region_il>source /usr/local/mysql/dba/imp/result_basic_schema.sql;
region_il>desc result_basic;
+-----------------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-----------------------+-------------+------+-----+---------+-------+
| result_id | int(11) | NO | PRI | NULL | |
| ppid | varchar(24) | YES | | NULL | |
| title | text | YES | | NULL | |
| categories | text | YES | | NULL | |
| phone | varchar(24) | YES | | NULL | |
| brand_code | varchar(24) | YES | | NULL | |
| street_address | text | YES | | NULL | |
| zip_code | varchar(24) | YES | | NULL | |
| city | text | YES | | NULL | |
| state | varchar(50) | YES | | NULL | |
| country | varchar(50) | YES | | NULL | |
| lat | double | YES | | NULL | |
| lon | double | YES | | NULL | |
| vendor_code | varchar(24) | YES | | NULL | |
| vendor_poi_id | varchar(32) | YES | MUL | NULL | |
| actual_street_address | text | YES | | NULL | |
| actual_zip_code | varchar(24) | YES | | NULL | |
| extender | text | YES | | NULL | |
| titles | text | YES | | NULL | |
+-----------------------+-------------+------+-----+---------+-------+
19 rows in set (0.01 sec)
6. 加载数据到MySQL表中
$ script /dev/null
$ screen -S restore_data
enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 33
Server version: 5.6.23-log MySQL Community Server (GPL) Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
region_il>LOAD DATA INFILE '/usr/local/mysql/dba/imp/result_basic.csv' INTO TABLE result_basic FIELDS TERMINATED BY '^' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\n';
Query OK, 2611527 rows affected (50 min 3.08 sec)
Records: 2611527 Deleted: 0 Skipped: 0 Warnings: 0
7. 验证导入的数据
region_il>select count(*) from result_basic;
+----------+
| count(*) |
+----------+
| 2611527 |
+----------+
1 row in set (0.94 sec)
region_il>select * from result_basic where result_id = 2\G
*************************** 1. row ***************************
result_id: 2
ppid: SUK5QD9B7C16D826B26E5
title: ????? ??????? ????????
categories: {791}
phone:
brand_code:
street_address: ???? ?????? ???? ?? ?????????
zip_code: 42314
city: ???????
state: ???????
country: SAU
lat: 24.47893
lon: 39.65331
vendor_code: NOCO
vendor_poi_id: 1040248605
actual_street_address:
actual_zip_code:
extender: {"sideOfStreet":"+","mapLinkId":"571732670"}
titles:
1 row in set (0.05 sec)
region_il>show variables like '%char%';
+--------------------------+----------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/local/mysql/share/charsets/ |
+--------------------------+----------------------------------+
8 rows in set (0.03 sec) region_il>set character_set_results = utf8;
Query OK, 0 rows affected (0.02 sec) region_il>select * from result_basic where result_id = 2\G
*************************** 1. row ***************************
result_id: 2
ppid: SUK5QD9B7C16D826B26E5
title: هندسة العمارة والديكور
categories: {791}
phone:
brand_code:
street_address: طريق الأمير مقرن بن عبدالعزيز
zip_code: 42314
city: المدينة
state: المدينة
country: SAU
lat: 24.47893
lon: 39.65331
vendor_code: NOCO
vendor_poi_id: 1040248605
actual_street_address:
actual_zip_code:
extender: {"sideOfStreet":"+","mapLinkId":"571732670"}
titles:
1 row in set (0.00 sec)
PostgreSQL导出一张表到MySQL的更多相关文章
- postgresql导出某张表的数据
\copy 表名 to 路径 with csv 比如: \copy dataset to /home/backup/dataset.csv with csv \copy dataset to /hom ...
- 利用sqlldr从MySQL导出一张表数据到Oracle
根据业务需求,需要从MySQL库中同步一张表tap_application到Oracle中,下面是记录的导入过程. 1. 查看MySQL表结构 desc tap_application; +----- ...
- Mysql导出(多张表)表结构及表数据 mysqldump用法
命令行下具体用法如下: mysqldump -u用戶名 -p密码 -d 數據库名 表名 脚本名; 1.导出數據库為dbname的表结构(其中用戶名為root,密码為dbpasswd,生成的脚 ...
- mysqldump批量导出(多张表)表结构及表数据
Mysql 批量导出表结构(数据) 仅导出结构,不导出数据: 1.导出數據库為dbname的表结构 mysqldump -h主机地址 -u用户名 -p密码 -d dbname >db.s ...
- mysql导出某张表的部分数据
.使用into outfile '保存到操作系统的外部文件路径' mysql -uroot -p123456 -hhostname -P3306 select column_name_list fro ...
- oracle EXP导出一张表时使用query参数指定where条件
oracle exp 导出一个表的部分内容,使用query参数可加上SQL的where条件进行过滤 注意:如果需要使用到日期字符串格式等单引号,需要使用双引号将where条件括起来,而且双引号要用\做 ...
- Oracle数据库中导出某张表到SQL并关联更新
首先想到查询出结果,然后导出为SQL文件: 先导出表结构 1 在桌面建立对应的sql空文件 2 toos-->export userObjects 3 在对话框中选择你要导出的表 4 勾选上si ...
- sql 脚本 oracle scott 用户的四张表导入 mysql 中
/* 要先删除emp表,不能先删除dept表,因为dept有一个外键关联emp表*/drop TABLE emp;drop TABLE dept; drop TABLE salgrade;drop T ...
- sqlplus 导出一张表数据
内网只让用sql developer 这软件搓的不行,数据加载到51行就黑了,没法法用sqlplus. 打开cmd, sqlplus user/passwd@ip:port/库名set colsep ...
随机推荐
- Linux下 查看CPU信息
参考: Linux和Windows下查看cpu和core个数 Linux下 查看CPU信息 1.查看完整CPU信息: $ cat /proc/cpuinfo 2.查看逻辑cpu个数: $ cat /p ...
- js转义和反转义html
本文地址: http://www.cnblogs.com/daysme/p/7100553.html 下面的代码网上常用有,但不是想要的. JS实现HTML标签转义及反转义 http://blog.c ...
- HDU 5459 Jesus Is Here(递推)
http://acm.hdu.edu.cn/showproblem.php?pid=5459 题意: S(1) = c,S(2) = ff, S(3) = cff,之后S(i) = S(i-1)+S( ...
- HDU 4302 Holedox Eating(multiset)
http://acm.hdu.edu.cn/showproblem.php?pid=4302 题意: 在一条直线上,会有多条命令,如果是0,那么就会在x位置处出现一个蛋糕,如果是1,某人就会找到最近的 ...
- mapgis IGServer账号
2064803644@qq.com 1576391020@qq.com 密码一样
- R 语言 Windows 环境 安装与Windows下制作R的package--Rtools
1.1 预装的软件 (所有软件都可以在 http://www.biosino.org/R/R-doc/Rm/ 和 http://www.biosino.org/R/requiredSoftWar ...
- 【Selenium2】【Python多线程】
# all_tests_pro.py import unittest,time,os,multiprocessingimport HTMLTestRunner #查找多有含有thread的文件,文件夹 ...
- mark mem
韦达定理 http://baike.baidu.com/link?url=M45ozZEnQ4BtKD7l22WWgQuGnmDYV7TFynQcPEO2Tt8leYGhyEa1flt-RM34NG4 ...
- SqlParameter的两种用法【二】
private void Loadprovince() { string sql = "select * from Tables where ArealdPid=@pid"; /第 ...
- 串口.Qt532测试(异步)
环境:Win7x64.Qt5.3.2 MSVC OpenGL(x86).vs2010(x86) 项目所在位置:E:\Project_Qt532\SeriesPort_Qt532_Z ZC:这里 同步方 ...