Connecting remote mysql database to local mysql databse? - mysql

I want to write a php code to be embedded in drupal7 module.
I want to call a procedure which can copy the newly generated data in local mysql database to the remote mysql database.
When data is inserted in tables 'A' of my local data base it should be copied to the specific table 'B' of the remote mysql server's database.
Table 'A' is on local host.
Table 'B' is on remote server.
insert data on 'A' -> copied data in 'B'
Is this possible?
Thanks for the help.

Trigger + Federated tables should do the trick:
http://dev.mysql.com/doc/refman/5.0/en/federated-use.html
http://dev.mysql.com/doc/refman/5.0/en/federated-limitations.html

If you're looking for automatic backups or master->slave duplication, there are ways to accomplish that without touching a line of code.
See here for how:
http://dev.mysql.com/doc/refman/5.0/en/replication-howto.html
This is my personal favorite:
http://blog.evandavey.com/2008/05/how-to-setup-mysql-replication-a-simple-guide.html
Related post:
phpmyadmin synchronize
Still need help doing that? Post.

Related

Accesing data from one mysql database to another in MYSQL Workbench

I have two different databases. I have to access data from one database and insert them into another ( with some data processing included, it is not only to copy data ) Also, the schema is really complex and each table has many rows, so copying data into schema in the second database is not an option. I have to do that using MySQL Workbench, so I have to do it using SQL queries. Is there a way to create a connection from one database to another and access its data?
While MySQL Workbench can be used to transfer data between servers (e.g. as part of a migration process) it is not useful when you have to process the data first. Instead you have 2 other options:
Use a dedicated tool you write yourself to do that (as eddwinpaz mentioned).
Use the capabilities of your server. That is, copy the data to the target server, into a temporary table (using dump and restore). Then use queries to modify the data as you need it. Finally copy it to the target table.

How to insert table values from one MySQL database to another MySQL database when they are on 2 different servers with different ports?

I have one MySQL db on server A and another MySQL instance on a server B. There is a need to copy records (fastest possible) from one table to another (based on user providing ID for records that match) from server A -> B many times during the day. Is there a way to create an SQL statement to do this or data need to be extracted by some programming language (e.g. Perl, Python etc.), then store result in variables and then prepare Insert statement in order to to insert data to server B?
Servers have 2 different IPs and DBs are on 2 different ports but they are the same version of MySQL (5.6.29).
you could use the replication facilities of MySQL
I don't have enough reputation to just comment, but I think the easiest approach would be to create a view on server A with just that data that server B needs, then create a cron job on server B to periodically query the view & import the data during the day. For the job on B I would suggest you script it and create logfiles for debugging, but you could just put a mysql command in your crontab if you want it quick and dirty.

inserting records from mysql table on remote database

I have two databases on two different servers, i wish to insert the records from table A on server2 to table B on server1, table A and B have identifical schema but different names.
how can this be done?
You can try following,
The Easiest approach as per my point is make .sql file from first server db.
Now Open that .sql file in note and find & replace the table name A with table name B.
Now execute that .sql file on the remote server 2.
I prefer to use linked server in this type of scenario.....Check out following url to implement linked server
http://www.sqlmag.com/article/sql-server/querying-tables-and-views-on-a-linked-server
http://www.quackit.com/sql_server/sql_server_2008/tutorial/linked_servers.cfm
http://msdn.microsoft.com/en-us/library/aa213778%28SQL.80%29.aspx

How to notify any change from One database to another database

Is it possible to notify a database from another database, both the database are on different server. and both the database are different type. eg. if i have a DB2 database on one server and some records are updated on this database than need to notify another DB and modify some table in on that DB(my case it is MYSql).
Thanks in advance
You can create a link between databases and using triggers - update corresponding data in the other database.
I would investigate replication, to see if mySQL can be a replication target for DB2.
Read introduction to SQL Replication.

Select from second MySQL Server

I would like to select data from a second MySQL database in order to migrate data from one server to another.
I'm looking for syntax like
SELECT * FROM username:password#serverip.databaseName.tableName
Is this possible? I would be able to do this in Microsoft SQL Server using linked servers, so I'm assuming it's possible in MySQL as well.
You can create a table using FEDERATED storage engine:
CREATE TABLE tableName (id INT NOT NULL, …)
ENGINE=FEDERATED
CONNECTION='mysql://username:password#serverip/databaseName/tableName'
SELECT *
FROM tableName
Basically, it will serve as a view over the remote tableName.
There are generally two approaches you can take, although neither of them sound like what you're after:
Use replication and set up a master/slave relationship between the two databases.
Simply dump the data (using the command line mysqldump tool) from the 1st database and import it into the 2nd.
However, both of these will ultimately migrate all of the data (i.e.: not a subset), although you can specify specific table(s) via mysqldump. Additionally, if you use the mysqldump approach and you're not using InnoDB you'll need to ensure that the source database isn't in use (i.e.: has integrity) when the dump is created.
You can't do this directly, but as someone else alluded to in a comment, you can use mysqldump to export the contents of a table as a SQL script.
At that point you could run the script on the new server to create the table, or if more manipulation of the data is required, import that data into a table with a different name on the new server, then write a query to copy the data from there.