表插入-多个mysql数据库

0h4hbjxa  于 2021-06-25  发布在  Mysql
关注(0)|答案(1)|浏览(353)

我正在使用下面的查询尝试从database2的table2向database1的table1插入几行。这两个表都有不同的模式。
两个表的结构都相同。我确实用类似的查询查看了其他帖子,但没有结果。使用以下基本方法:

INSERT INTO    remoteDATABASE.remoteSCHEMA.remoteTABLE
  SELECT  * FROM    localTABLE

INSERT INTO 'eno*****.com'.asdf_stage.temp 
SELECT i.artf_id as  id,
    title as description,
    (case 
        when i.assigned_group = 'asdfk' then 'dfg'
        when i.assigned_group = 'dfgdg' then 'dgdk'
        when i.assigned_group = 'dfghdgf' then 'igo'
        when i.assigned_group = 'dfgh' then 'eMgem'
        when i.assigned_group = 'Edsfg' then 'esgd'
        end ) as area,
    "N/A" as disposition,
   "********" as flavor,
   "ipf" as link,
   "*************" as vendor,
    DATE(date_created) date,
  DATE(close_date) as completed
  FROM******com.lkjhg_stage.issues  i
    where date(date_created) >'2018-04-01' AND status!='Rejected'

我得到语法错误,需要知道什么是正确的语法提到数据库名,架构名和表名在这两个地方。另外,表有大约10-15列,我需要指定所有列吗?

2exbekwf

2exbekwf1#

用单引号替换双引号。date不是函数,保留字date不是一个好的列名。
将表引用为server.database.owner.object

INSERT INTO SERVER1.DATABASE1.OWNER1.OBJECT1
SELECT * FROM localTABLE

INSERT INTO SERVER1.DATABASE1.OWNER1.OBJECT1
SELECT i.artf_id as id,
    title as description,
    (case 
        when i.assigned_group = 'asdfk' then 'dfg'
        when i.assigned_group = 'dfgdg' then 'dgdk'
        when i.assigned_group = 'dfghdgf' then 'igo'
        when i.assigned_group = 'dfgh' then 'eMgem'
        when i.assigned_group = 'Edsfg' then 'esgd'
        end ) as area,
    'N/A' as disposition,
   '********' as flavor,
   'ipf' as link,
   '*************' as vendor,
    date_created,
    close_date as completed
FROM SERVER2.DATABASE2.OWNER2.OBJECT2  i
WHERE date_created > '2018-04-01' AND status != Rejected'

相关问题