inserting records from mysql table on remote database - mysql

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

Related

how to load dataset on top of existing dataset in MySQL DB?

I have 2 MYSQL server A and B, and both have a table of the same name
and same DB schema.
Server A has 3000 rows while server B has 10000+rows.
In regarding these rows, they do not have any overlap. Both are unique dataset.
And I have already execute "mysqldump ... " to have Server A's data dumped in a file, so what is the easy way for me to load Server A's data on this table into Server B, on top of the existing Server B dataset ? Is there a command way to do that ?
When making the dump, use the --no-create-info option. This leaves out the DROP TABLE and CREATE TABLE statements in the dump file that would remove the existing table.
The dump file will then just contain the INSERT statements, which will append to the existing table.
If you can't recreate the dump file, open it in an editor and delete those statements.

How to take backup of Single table in SSIS Package

I want to take backup of single table on same server but in different backup database, backup table name should like "tablename_currentdate+7". Also I want to check if backup table is present in backup database or not. If yes I want to drop that table.
Please suggest how to perform this task in SSIS package.
Establish a connection to both databases
I would suggest creating a table in the backup database and always use it. something like tablename_BU
Exec SQL Object to TRUNCATE the table
put in a data flow
connect to source and select * from TABLE
Put in a destination and map.
VIOLA

MySQL "source" command overwrites table

I have a MySQL Server which has one database called "Backup".
It only has one table with the name "storage".
In the Backup db the storage table contains about 5 Millions datarows.
Now I wanted to append new rows to the table by using the "source" command in the SQL command line.
So what happend is, that source uploaded all the new files in the table, but it overwrote the existing entries (seems that he first deleted all data)
What I have to say is that the sql file that I want to update comes from another server where this table has the same name and structure as "storage".
What I want is to append the new entries that are in the sql file to the one in my datebase. I do not want to overwrite them.
The structure in the two tables is exactly the same. I use the Backup datebase as the name says for backup uses, so that from time to time I can backup my data.
Has anyone an idea how to solve this?
Look in the .sql file you're reading with the SOURCE command, and remove the DROP TABLE and CREATE TABLE statements that appear there. They are the cause of your table being overwritten; what's actually happening is that the table is being replaced.
You could also look into using SELECT ... INTO OUTFILE and LOAD DATA INFILE as a faster and less potentially destructive way to get data from one server to the other in a file.

Connecting remote mysql database to local mysql databse?

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.

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.