Select on one server, Insert on another

Asked

Viewed 710 times

0

I use the following query to select data from one database and insert into another:

insert into banco_novo.cliente (codcliente, nome, cpf, rg, sexo, data_nascimento, endereco, bairro, cidade, estado, cep)
select codcliente, nome, cpf, rg, IFNULL(sexo, 'I'), IFNULL(data_nascimento, '2000-01-01'), endereco, bairro, cidade, IFNULL(estado, '0'), cep 
from banco_antigo.cliente

I now need to select a database on one server and insert it into another database on another server.
I tried so:

insert into servidor_novo.banco_novo.cliente (codcliente, nome, cpf, rg, sexo, data_nascimento, endereco, bairro, cidade, estado, cep)
select codcliente, nome, cpf, rg, IFNULL(sexo, 'I'), IFNULL(data_nascimento, '2000-01-01'), endereco, bairro, cidade, IFNULL(estado, '0'), cep
from servidor_antigo.banco_antigo.cliente

But to no avail.

I have Workbench connected with both servers, but I do not know how to execute the query to do this operation.

  • Tried to INSERT INTO bancox.tabela (SELECT * FROM bancoy.tabela)?

  • Two banks on the same server is OK. But two banks on two different servers that is BO

  • Now that I understand. I understand 2 banks, not 2 banks on separate servers.

  • For different servers will not work directly. You will have to extract the inserts and run on the other connection.

  • 2
  • If you want to run queries on different Databases, it would not be the case to just use the "use database1" clause and then "use database2". before the honey that will spin?

  • @Rafaelsalomão In a query only I can do this ?

  • @Rafaelsalomão, what he needs is different servers and not just different banks.

  • Is it because I don’t get it, it’s two Databases on the same server ? Or two distinct banks one on each server ? Ahhhhhhhhhhhhhh

  • In this case on different servers would have to have two different connections!

  • @Rbz, never used this link, whenever I needed to do something similar, I did it via Excel or extracting the inserts, but it seems to be a way out, I’ll even save the link in the bookmarks.

  • @Robertodecampos Neither do I! If you do tests, then tell me?

  • I’ll let you know in chat.

Show 8 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.