一项目客户是oracle数据库,需要导一个表数据到自研系统mysql数据库,甲方已给出oracle格式dmp文件!
处理思路:
①、安装Oracle数据库。
②、用甲方提供oracle格式dmp文件导入我方自搭建的Oracle。
③、安装一台mysql数据库或使用现成的MySQL数据库。
④、使用Navicat工具,使用 工具数据传输功能将Oracle数据传输至mysql!
忽略此步骤,度娘一堆安装教程。
大致就是使用Centos7桌面服务器安装。
参考连接:https://www.cnblogs.com/nmlwh/p/11923553.html#top
备份还原参考:https://www.cnblogs.com/xiaohuizhenyoucai/p/11100750.html
①、使用imp命令导入
[oracle@localhost mnt]$ imp system/*******@abc file=/mnt/sxgddzhdaochu20220302.dmp ignore=y full=y
system:oracle用户
*****:代表密码
@abc:数据导入abc数据库
file:导入文件绝对路径。
报错:
[oracle@localhost mnt]$ imp system/aaaAAA3451@abc file=/mnt/sxgddzhdaochu20220302.dmp ignore=y full=y
Import: Release 12.1.0.2.0 - Production on Tue Mar 8 21:14:59 2022
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
Warning: the objects were exported by SXGDDZH, not by you
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses AL32UTF8 character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
. importing SXGDDZH's objects into SYSTEM
. importing SXGDDZH's objects into SYSTEM
. . importing table "WO_ORDER"
IMP-00019: row rejected due to ORACLE error 12899
IMP-00003: ORACLE error 12899 encountered
ORA-12899: value too large for column "SYSTEM"."WO_ORDER"."CALLIN_CODE" (actual: 33, maximum: 30)
原因分析:
大致就是dmp文件的字符集和搭建出来创建好的abc数据库字符集不符合,所以报错!
解决办法:
SQL>connect username/password as SYSDBA;
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP MOUNT;
SQL>ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL>ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
SQL>ALTER SYSTEM SET AQ_TM_PROCESSES=0;
SQL>ALTER DATABASE OPEN;
SQL> ALTER DATABASE CHARACTER SET ZHS16GBK ;
ALTER DATABASE CHARACTER SET ZHS16GBK;
*ERROR at line 1:
ORA-12712: new character set must be a superset of old character set
此时报错,不必慌张。提示新字符集必须是超集,此时INTRENAL_USE指令不对字符集超集进行检查。输入以下命令即可:
SQL>ALTER DATABASE CHARACTER SET INTERNAL_USE ZHS16GBK;
SQL>SHUTDOWN IMMEDIATE;
SQL>STARTUP;
修改后再次导入:
[oracle@localhost mnt]$ imp system/aaaAAA3451@abc file=/mnt/sxgddzhdaochu20220302.dmp ignore=y full=y
Import: Release 12.1.0.2.0 - Production on Tue Mar 8 21:45:49 2022
Copyright (c) 1982, 2014, Oracle and/or its affiliates. All rights reserved.
Connected to: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production
With the Partitioning, OLAP, Advanced Analytics and Real Application Testing options
Export file created by EXPORT:V11.02.00 via conventional path
Warning: the objects were exported by SXGDDZH, not by you
import done in US7ASCII character set and AL16UTF16 NCHAR character set
import server uses ZHS16GBK character set (possible charset conversion)
export client uses ZHS16GBK character set (possible charset conversion)
. importing SXGDDZH's objects into SYSTEM
. importing SXGDDZH's objects into SYSTEM
. . importing table "WO_ORDER" 1540160 rows imported
Import terminated successfully without warnings.
通过Navicat 管理工具查看,已经有WO_ORDER表!
①、拉取mysql镜像
[oracle@localhost mnt]$ docker pull mysql:5.7.20
②、运行mysql容器
[root@localhost ~]# docker run -d -p 3306:3306 --name mysql -v /opt/mysql/data:/var/lib/mysql -v /opt/mysql/logs:/var/log/mysql -v /opt/mysql/conf:/etc/mysql/mysql.conf.d -e MYSQL_ROOT_PASSWORD=123456 mysql:5.7.20
注:记得关闭selinux,否则可能会报错。
③、进入mysql容器授权mysql root用户可远程连接
[root@localhost ~]# docker exec -it mysql sh
# mysql -uroot -p
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
此时,使用Navicat 工具连接mysql成功。
两个数据库语法不同,表字段类型也不同,如果公国Navicat工具导出、导入会有很多报错!
①、数据传输
选择传输的源和目标
选择需要同步的表
开始
报错:
[ERR] 1> 1170 - BLOB/TEXT column 'BLANK3' used in key specification without a key length
报错原因可参考:https://blog.csdn.net/helloxiaozhe/article/details/83018347
大致就是建索引、约束这些有问题了!
解决办法:
取消建索引、外键约束即可!
去掉索引和约束之后在开始数据就会从Oracle传输至MySQL了!好了文章到这里就结束了!
剩下的就是mysql导出表数据同步到项目mysql的事情了!
插曲
Navicate 连接Oracle可能会有报错,大致意思就是oci驱动太老了,需要上oracle官网下载oci驱动!
报错提示是:ORA-28547:connection to server failed, probable Oracle Net admin error
上网一查原来是oci.dll版本不对。因为Navicat是通过Oracle客户端连接Oracle服务器的,Oracle的客户端分为两种,一种是标准版,一种是简洁版,即Oracle Install Client。而我们用Navicat时通常会在自己的安装路径下包含多个版本的OCI,如果使用Navicat连接Oracle服务器出现ORA-28547错误时,多数是因为Navicat本地的OCI版本与Oracle服务器服务器不符造成的。所以我们要做的就是下载OCI使之与我们所安装的Oracle服务器相符合。
下载地址:https://www.oracle.com/database/technologies/instant-client/downloads.html
下载64位安装包:
选择第一个
下载后解压
打开Navicate,依次点击工具----选项----环境 OCI选择刚下载的oci文件。
OK,按以上操作基本就可以了。