首先看看有没有federated 引擎:
- mysql> show engines;
- +--------------------+---------+------------------------------------------------------------+--------------+-----+------------+
- | Engine | Support | Comment | Transactions | XA | Savepoints |
- +--------------------+---------+------------------------------------------------------------+--------------+-----+------------+
- | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
- | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
- | CSV | YES | CSV storage engine | NO | NO | NO |
- | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
- | MyISAM | YES | MyISAM storage engine | NO | NO | NO |
- | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
- +--------------------+---------+------------------------------------------------------------+--------------+-----+------------+
- 6 rows in set
看到没有安装federated存储引擎(目标端可以是任何的存储引擎比如说myisam或者innodb)
安装federated存储引擎:
- mysql> install plugin federated soname 'ha_federated.so';
- Query OK, 0 rows affected
- mysql>
测试一下是否可以
- [root@test01 bin]# ./mysqld_safe --federated &
- [1] 5418
- You have new mail in /var/spool/mail/root
- [root@test01 bin]# 170823 16:24:17 mysqld_safe Logging to '/var/log/mysqld.log'.
- 170823 16:24:17 mysqld_safe Starting mysqld daemon with databases from /mysql/data
- 170823 16:25:57 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
默认mysql是没有开启federated存储引擎【linux系统下】
- mysql> show engines ;
- +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
- | Engine | Support | Comment | Transactions | XA | Savepoints |
- +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
- | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
- | FEDERATED | NO | Federated MySQL storage engine | NULL | NULL | NULL |
- | CSV | YES | CSV storage engine | NO | NO | NO |
- | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
- | MyISAM | YES | MyISAM storage engine | NO | NO | NO |
- | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
- | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
- +--------------------+---------+------------------------------------------------------------+--------------+------+------------+
- 7 rows in set
- mysql>
先找到my.cnf文件,我这里直接搜索的。【linux系统下】
- [root@test01 mysql]# find / -name my.cnf
- /mysql/mysql-5.5.47/packaging/rpm-sles/my.cnf
- /mysql/mysql-5.5.47/packaging/rpm-docker/my.cnf
- /mysql/mysql-5.5.47/packaging/rpm-oel/my.cnf
- /mysql/mysql-5.5.47/mysql-test/suite/federated/my.cnf
- /mysql/mysql-5.5.47/mysql-test/suite/rpl/my.cnf
- /mysql/mysql-test/suite/federated/my.cnf
- /mysql/mysql-test/suite/rpl/my.cnf
- /etc/my.cnf
- [root@test01 mysql]#
开启federated存储引擎
只需要在my.cnf文件中增加 federated 就可以。【linux系统下】
- [mysqld]
- datadir=/mysql/data
- socket=/mysql/data/mysql.sock
- user=mysql
- # Disabling symbolic-links is recommended to prevent assorted security risks
- symbolic-links=0
- lower_case_table_names=1
- [mysqld_safe]
- log-error=/var/log/mysqld.log
- pid-file=/var/run/mysqld/mysqld.pid
- federated
配置好my.cnf文件的federated,然后重启mysql服务。
- [root@test01 ~]# service mysql restart
- mysql: 未被识别的服务
- You have new mail in /var/spool/mail/root
- [root@test01 ~]#
重启的时候提示:未被识别的服务,解决方法如下:
- [root@test01 support-files]# pwd
- /mysql/support-files
- [root@test01 support-files]# cp ./mysql.server /etc/init.d/mysqld
- [root@test01 support-files]# chkconfig --add mysqld
- [root@test01 support-files]# chkconfig --level 2345 mysqld on
- [root@test01 support-files]#
使用service mysqld restart --federated 命令重启mysql
- [root@test01 ~]# service mysqld restart --federated
- Shutting down MySQL... [确定]
- Starting MySQL.. [确定]
- [root@test01 ~]#
查看 federated 服务是否启动了。
- mysql> show engines ;
- +--------------------+---------+------------------------------------------------------------+--------------+-----+------------+
- | Engine | Support | Comment | Transactions | XA | Savepoints |
- +--------------------+---------+------------------------------------------------------------+--------------+-----+------------+
- | InnoDB | DEFAULT | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
- | FEDERATED | YES | Federated MySQL storage engine | NO | NO | NO |
- | CSV | YES | CSV storage engine | NO | NO | NO |
- | MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
- | MyISAM | YES | MyISAM storage engine | NO | NO | NO |
- | MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
- | PERFORMANCE_SCHEMA | YES | Performance Schema | NO | NO | NO |
- +--------------------+---------+------------------------------------------------------------+--------------+-----+------------+
- 7 rows in set
- mysql>
好了,FEDERATED值为YES了。
目标:本地库A的三张表,整合数据后,写入远程库B的一张表中。
下面我们来建表
远程库B的inf_monitor_data表:
- DROP TABLE IF EXISTS `inf_monitor_data`;
- CREATE TABLE `inf_monitor_data` (
- `id` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '编号',
- `IT_Catalog` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '主类别',
- `IT_Function` varchar(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '子类别',
- `Business_Name` varchar(200) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '业务名称',
- `Control_Address` varchar(300) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '管理地址,设备Ip|数据库服务名|URI地址',
- `Title` varchar(300) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '摘要',
- `Detail` varchar(2000) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '描述',
- `Start_Time` datetime NOT NULL COMMENT '采集查询起始时间',
- `End_Time` datetime DEFAULT NULL COMMENT '采集查询结束时间',
- `BSM_Type` varchar(100) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '对应其是哪类监视器的事件',
- `Status` varchar(3) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '处理标记',
- `Remarks` varchar(300) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL COMMENT '备注',
- PRIMARY KEY (`id`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
本地库A的c_itcomp、def_comp、i_incident表:
- DROP TABLE IF EXISTS `c_itcomp`;
- CREATE TABLE `c_itcomp` (
- `P_Guid` varchar(40) NOT NULL COMMENT '主键,唯一标识',
- `AF_Pid` varchar(40) DEFAULT NULL COMMENT '部件的父设备',
- `D_AVA_STATE` int(11) DEFAULT NULL,
- `D_CAP_STATE` int(11) DEFAULT NULL,
- `Com_Duration` decimal(18,0) DEFAULT NULL COMMENT '本次持续时间,下一次变化维护,毫秒',
- `Com_StartTime` datetime DEFAULT NULL COMMENT '本次变化的开始时间',
- `Com_EndTime` datetime DEFAULT NULL COMMENT '下一次变化的开始时间,下一次变化时维护',
- `Com_Role` varchar(40) DEFAULT NULL,
- `Com_A_IsUserComfirmed` bit(1) DEFAULT NULL COMMENT '用户是否已确认',
- `A_CanManage` bit(1) DEFAULT NULL COMMENT '是否可网管',
- `A_CanMonitor` bit(1) NOT NULL COMMENT '是否可监视,有监视调度维护,无可连通凭证则不可监视',
- `A_IsStop` bit(1) DEFAULT NULL COMMENT '是否停止监视',
- `A_CIChanged` int(11) DEFAULT NULL COMMENT 'CI相对基线是否发生变化(1=未变更,2=已知变更,3=未知变更)',
- `A_IsEdge` bit(1) DEFAULT NULL COMMENT '是否是边缘交换机',
- `D_BusinessName` varchar(50) DEFAULT NULL COMMENT '业务名称',
- `D_Useage` varchar(500) DEFAULT NULL COMMENT '组件用途',
- `D_Descr` varchar(1000) DEFAULT NULL COMMENT '描述,snmp获取或用户自定义',
- `D_BusinessCode` varchar(200) DEFAULT NULL COMMENT '业务编码',
- `D_HostName` varchar(50) DEFAULT NULL COMMENT '设备名称,设备自身定义的名称',
- `D_ControlAdderss` varchar(200) DEFAULT NULL COMMENT '管理地址,设备Ip|数据库服务名|URI地址',
- `DE_UseState` int(11) DEFAULT NULL COMMENT '组件使用状态,枚举:ITCompState',
- `DF_DutyRole` varchar(1000) DEFAULT NULL COMMENT '责任角色,外键,角色唯一标识',
- `DF_DutyUser` varchar(2000) DEFAULT NULL COMMENT '责任人,外键,人员唯一标识',
- `DE_ITCatalog` int(11) DEFAULT NULL COMMENT '主类别,枚举:ITCompCatalog',
- `DE_ITFunction` int(11) DEFAULT NULL COMMENT '子类别,枚举:ITCompFunction',
- `DE_ITManufacturer` int(11) DEFAULT NULL COMMENT '厂商,枚举:ITCompManufacturer',
- `DE_ITProductSeries` int(11) DEFAULT NULL COMMENT '产品系列,枚举:ITCompProductSeries',
- `D_Version` varchar(100) DEFAULT NULL COMMENT '版本号',
- `DF_Path_Site` varchar(150) DEFAULT NULL COMMENT '外键,Site类别路径的唯一标识,格式:[id#id#id]',
- `DF_Path_Location` varchar(150) DEFAULT NULL COMMENT '外键,Location类别路径的唯一标识,格式:[id#id#id]',
- `DF_Path_Custom` varchar(150) DEFAULT NULL COMMENT '外键,Custom类别路径的唯一标识,格式:[id#id#id]',
- `DF_Right_R` varchar(800) NOT NULL COMMENT '权限读,角色唯一标识,格式:[''id'',''id'',''id'']|[all]|[none]',
- `DF_Right_W` varchar(800) NOT NULL COMMENT '权限写,角色唯一标识,格式:[''id'',''id'',''id'']|[all]|[none]',
- `D_CPU_Unilization` decimal(18,0) DEFAULT NULL COMMENT 'CPU使用率',
- `D_Mem_Unilization` decimal(18,0) DEFAULT NULL COMMENT '内存使用率',
- `D_CPU_State` int(11) DEFAULT NULL,
- `D_Mem_State` int(11) DEFAULT NULL,
- `D_CIP_Building` varchar(100) DEFAULT NULL COMMENT '建筑物',
- `D_CIP_Floor` varchar(50) DEFAULT NULL COMMENT '楼层',
- `D_CIP_OPSystem` varchar(50) DEFAULT NULL COMMENT '操作系统',
- `D_CIP_Bed` varchar(50) DEFAULT NULL COMMENT '机架',
- `D_CIP_SlotInBed` varchar(50) DEFAULT NULL COMMENT '机架上的槽位',
- `D_CIP_Room` varchar(50) DEFAULT NULL COMMENT '房间',
- `DF_CreateUserId` varchar(40) DEFAULT NULL COMMENT '创建人',
- `D_CreateTime` datetime DEFAULT NULL COMMENT '创建时间',
- `DF_UpdateUserId` varchar(40) DEFAULT NULL COMMENT '修改人',
- `D_UpdateTime` datetime DEFAULT NULL COMMENT '修改时间',
- `DF_CheckUserId` varchar(40) DEFAULT NULL COMMENT '检查人',
- `D_CheckTime` datetime DEFAULT NULL COMMENT '检查时间',
- `D_Price` decimal(18,2) DEFAULT NULL COMMENT '单价',
- `D_UsefulYear` decimal(18,2) DEFAULT NULL COMMENT '使用年限',
- `D_NetSalvageValue` decimal(18,2) DEFAULT NULL COMMENT '净残值',
- `D_ExternalSN` varchar(100) DEFAULT NULL COMMENT '资产_外部序列号',
- `D_ProductSN` varchar(100) DEFAULT NULL COMMENT '资产_产品序列号',
- `D_Brand` varchar(100) DEFAULT NULL COMMENT '资产_品牌',
- `D_BuyTime` datetime DEFAULT NULL COMMENT '购买日期',
- `D_BuyCost` decimal(18,2) DEFAULT NULL COMMENT '购买成本',
- `D_WarrantyTime` datetime DEFAULT NULL COMMENT '保修期',
- `DF_CostCustomer` varchar(200) DEFAULT NULL COMMENT '成本客户,从角色中选择,多个RoleID用逗号隔开',
- `DF_CostUser` varchar(200) DEFAULT NULL COMMENT '成本用户,从用户中选择,多个UserID用逗号隔开',
- `D_ImageUrl` varchar(100) DEFAULT NULL,
- `D_RunTime` decimal(18,0) DEFAULT NULL COMMENT '系统运行时间(秒)',
- `D_AssetCode` varchar(100) DEFAULT NULL COMMENT '资产编码,资产号',
- `D_ProviderOrg` varchar(40) DEFAULT NULL COMMENT '供应商',
- `D_BuyContract` varchar(40) DEFAULT NULL COMMENT '购买合同',
- `D_ServiceOrg` varchar(40) DEFAULT NULL COMMENT '服务商',
- `D_ServiceRole` varchar(40) DEFAULT NULL COMMENT '服务角色',
- `D_ServiceContract` varchar(40) DEFAULT NULL,
- `D_OldAssetValue` decimal(18,2) DEFAULT NULL COMMENT '原资产价值',
- `D_FixedAssetValue` decimal(18,2) DEFAULT NULL COMMENT '固定资产价值',
- `D_CIP_BusinessDepart` varchar(40) DEFAULT NULL COMMENT '归口业务部门',
- `D_CIP_Cabinets` varchar(50) DEFAULT NULL COMMENT '机柜',
- `D_CIP_Model` varchar(50) DEFAULT NULL COMMENT '设备型号',
- `D_CIP_CPU` varchar(50) DEFAULT NULL COMMENT 'CPU型号',
- `D_CIP_Memory` varchar(50) DEFAULT NULL COMMENT '内存',
- `D_CIP_HDD` varchar(50) DEFAULT NULL COMMENT '硬盘',
- `D_CIP_NIC` varchar(50) DEFAULT NULL COMMENT '网卡',
- `D_CIP_FiberCard` varchar(50) DEFAULT NULL COMMENT '光纤卡',
- `D_CIP_Power` varchar(50) DEFAULT NULL COMMENT '电源',
- `D_CIP_UsedPowerCount` varchar(50) DEFAULT NULL COMMENT '已通电电源数量',
- `D_CIP_DataBase` varchar(50) DEFAULT NULL COMMENT '数据库',
- `D_CIP_Middleware` varchar(50) DEFAULT NULL COMMENT '中间件',
- `D_CIP_Administrator` varchar(50) DEFAULT NULL COMMENT '管理员',
- `D_CIP_Developer` varchar(50) DEFAULT NULL COMMENT '开发人员',
- `D_CIP_StartUseTime` varchar(50) DEFAULT NULL COMMENT '开始使用时间',
- `D_CIP_ServiceStartTime` varchar(50) DEFAULT NULL COMMENT '维保开始时间',
- `D_CIP_ServiceEndTime` varchar(50) DEFAULT NULL COMMENT '维保终止时间',
- `D_CIP_ServiceProvider` varchar(150) DEFAULT NULL COMMENT '维保商',
- `D_CIP_Contact` varchar(150) DEFAULT NULL COMMENT '联系人',
- `D_CIP_ContactTel` varchar(150) DEFAULT NULL COMMENT '联系电话',
- `D_IPLong` decimal(18,0) DEFAULT NULL,
- `D_ControlUrl` varchar(200) DEFAULT NULL,
- `Com_AvaF` int(11) DEFAULT NULL COMMENT 'ava监视频率',
- `Com_CapF` int(11) DEFAULT NULL COMMENT 'Cap监视频率',
- `DF_LinkTopoID` varchar(50) DEFAULT NULL,
- `D_CIP_BatchNumber` varchar(50) DEFAULT NULL,
- `F_RUserID` varchar(1000) DEFAULT NULL,
- `F_RUserTEXT` varchar(1000) DEFAULT NULL,
- `F_RRoleID` varchar(40) DEFAULT NULL,
- `F_SUserID` varchar(500) DEFAULT NULL,
- `F_SUserTEXT` varchar(100) DEFAULT NULL,
- `F_SRoleID` varchar(40) DEFAULT NULL,
- `F_CUserID` varchar(500) DEFAULT NULL,
- `F_CUserTEXT` varchar(100) DEFAULT NULL,
- `F_CRoleID` varchar(40) DEFAULT NULL,
- `F_IUserID` varchar(500) DEFAULT NULL,
- `F_IUserTEXT` varchar(100) DEFAULT NULL,
- `F_IRoleID` varchar(40) DEFAULT NULL,
- `F_VUserID` varchar(500) DEFAULT NULL,
- `F_VUserTEXT` varchar(100) DEFAULT NULL,
- `F_VRoleID` varchar(40) DEFAULT NULL,
- `F_AUserID` varchar(500) DEFAULT NULL,
- `F_AUserTEXT` varchar(100) DEFAULT NULL,
- `F_ARoleID` varchar(40) DEFAULT NULL,
- `D_Affect` varchar(40) DEFAULT NULL,
- `D_Urgency` varchar(40) DEFAULT NULL,
- `DF_LifeCycle` varchar(40) DEFAULT NULL COMMENT '生命周期,对应d_itcomp_lifecycle',
- `D_SupportCompModel` varchar(40) DEFAULT NULL,
- `D_CIP_SlotCount` int(11) DEFAULT NULL COMMENT '网络设备的槽位数',
- `D_ExpiryDate` datetime DEFAULT NULL COMMENT '到期时间',
- `AF_SlaId` varchar(40) DEFAULT NULL,
- `D_SyslogEncoding` varchar(40) DEFAULT NULL,
- `D_IsReceiveLog` bit(1) DEFAULT NULL,
- `D_ReceiveLogParameter` varchar(100) DEFAULT NULL,
- `D_LastReceiveLogTime` varchar(40) DEFAULT NULL,
- `D_Barcode` varchar(50) DEFAULT NULL COMMENT '1D条形码',
- `A_IsBackup` bit(1) DEFAULT NULL COMMENT '是否是备件,true:备件;false:不是备件',
- `D_ClusterName` varchar(200) DEFAULT NULL COMMENT '集群名称(Vmware用)',
- `D_UID` varchar(100) DEFAULT NULL,
- `DE_VirtualType` int(11) DEFAULT NULL,
- PRIMARY KEY (`P_Guid`),
- UNIQUE KEY `c_itcomp_KEY` (`P_Guid`),
- KEY `x_A_CanManage` (`A_CanMonitor`),
- KEY `x_Com_A_IsUserComfirmed` (`Com_A_IsUserComfirmed`),
- KEY `x_Custom` (`DF_Path_Custom`),
- KEY `x_D_ControlAdderss` (`D_ControlAdderss`),
- KEY `x_DE_ITFunction` (`DE_ITFunction`),
- KEY `x_Loction` (`DF_Path_Location`),
- KEY `x_Site` (`DF_Path_Site`),
- KEY `IT_ITComp_D_Barcode` (`D_Barcode`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED;
- DROP TABLE IF EXISTS `def_comp`;
- CREATE TABLE `def_comp` (
- `P_Guid` varchar(40) NOT NULL COMMENT '主键,唯一标识',
- `AF_Pid` varchar(40) NOT NULL COMMENT '外键,父节点,如果是根节点则为 Root',
- `D_Key` varchar(20) DEFAULT NULL COMMENT '不是Id,是有意义的唯一标识',
- `D_Caption` varchar(20) DEFAULT NULL COMMENT '别名,默认为D_key',
- `DF_ITCatalog` int(11) DEFAULT NULL COMMENT '主类别,枚举:ITCompCatalog',
- `DF_ITFunction` int(11) DEFAULT NULL COMMENT '子类别,枚举:ITCompFunction',
- `DF_ITManufacturer` int(11) DEFAULT NULL COMMENT '厂商,枚举:ITCompManufacturer',
- `DF_ITProductSeries` int(11) DEFAULT NULL COMMENT '产品系列,枚举:ITCompProductSeries',
- `A_FacePlateId` varchar(50) DEFAULT NULL,
- `A_NeedParent` bit(1) DEFAULT NULL,
- `D_KeyWord` varchar(2000) DEFAULT NULL,
- PRIMARY KEY (`P_Guid`),
- UNIQUE KEY `def_comp_KEY` (`P_Guid`),
- KEY `x_Def_Comp_D_Key` (`D_Key`)
- ) ENGINE=InnoDB DEFAULT CHARSET=utf8 ROW_FORMAT=COMPRESSED;
- DROP TABLE IF EXISTS `i_incident`;
- CREATE TABLE `i_incident` (
- `P_Guid` varchar(40) NOT NULL COMMENT '主键,唯一标识',
- `D_Owner` varchar(40) DEFAULT NULL COMMENT '所有者,单选一个用户(不是角色)',
- `D_Title` varchar(300) NOT NULL COMMENT '摘要',
- `D_Title_Confirm` varchar(300) DEFAULT NULL COMMENT '摘要,工程师确认',
- `AE_ChannelModule` int(11) NOT NULL COMMENT '来源模块,枚举ChannelModule:1=Monitor,2=NetWork,3=Syslo
分享文章:用MySQL实现类似于Oracledblink的功能
网站URL:http://www.shufengxianlan.com/qtweb/news41/329591.html网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联