I have two MySQL databases DB1 and DB2, DB1 is on Online server, and DB2 is on local machine(localhost), Now i want to insert some data into DB2's table named db2_table from DB1's table named db1_table using MySQL QUERY. So it is possible or not?
Asked
Active
Viewed 207 times
2
-
It is possible. Do you have phpMyAdmin installed or do you have only command line interface? – caramba Oct 02 '17 at 11:45
-
yes..i have installed phpMyAdmin – Ajith Deivam Oct 02 '17 at 11:49
-
Actually this might be what you are looking for if command line: https://stackoverflow.com/a/6683000/2008111 and if you have phpMyAdmin just go to export, advanced, select the tables you need to export and then in other DB go to import. – caramba Oct 02 '17 at 11:49
-
I am working on a project in which the client requires an online as well as an offline application. Offline application data will be manually synced to online database linked to the web application. – Ajith Deivam Oct 02 '17 at 11:51
-
If you want both databases to be kept identifcal, it sounds vaguely like you're looking for replication. Have you looked up MySQL replication? – Chris J Oct 02 '17 at 12:15
-
yes..I have 2 servers, one of which is a Master and the other which is a Slave. We tell the Master that it should keep a log of every action performed on it. We tell the slave server that it should look at this log on the Master and whenever something new happens, it should do the same thing. – Ajith Deivam Oct 02 '17 at 12:23
1 Answers
1
if you are on the same server you can do something like
INSERT INTO DB2.db2_table (col1, col2, ..., colN) SELECT col1, col2 FROM DB1.db1_table WHERE ...
but being on different servers you can not insert data in this way... the simplest way I can think of, is to dump data from the source db (with phpmyadmin, for instance) and import it into the target db.

Roberto Bisello
- 1,235
- 10
- 18
-
-
I am working on a project in which the client requires an online as well as an offline application. Offline application data will be manually synced to online database linked to the web application. – Ajith Deivam Oct 02 '17 at 11:58
-
@kmgkumar: ops! there were too many parentheses (answered in hurry during lunch break), edited, thanks! – Roberto Bisello Oct 02 '17 at 13:55