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.
Related
I have a mysqldump backup that was created using --no-create-info option. I want to restore it to a new database that does not have certain tables (approximately 50 tables remove from target database as they were no longer needed).
So I am getting Table 'table_name' doesn't exist for the obvious reason.
So what is the mysql way of restoring to a database that does not have all the tables present in backup file.
I may user --insert-ignore to avoid this failure but I doubt this may also ignore some genuine errors such as data type mismatch etc.
You cannot insert rows to a table that doesn't exist, obviously.
To restore the data in your dump file, you need to create those tables first. You could go back to your source MySQL instance and dump those table definitions with mysqldump --no-data
If you don't care about the data, and you only want to restore data for tables that do exist, then you could filter out the INSERT statements before trying to import that script.
You could use grep -v for example to eliminate the rows.
Or you could use sed to delete lines between "-- Dumping data for table tablename" and whatever the next table is.
If you don't want to filter the data but you don't care about restoring data for the tables that don't exist, you could create dummy tables with the right fields, but define the tables with the BLACKHOLE storage engine, so the INSERTs won't actually result in saving any data.
One more option: Import the dump file with mysql --force so it continues even if it gets errors on some of the INSERTs.
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
I have a view in my production replica (it's a read-only database) and I need to copy one of the views to my data warehouse.
What would be the best way to go about it?
I can not create a table from the view on the replica. Meaning I can not do CREATE TABLE Table_From_View AS SELECT * FROM My_View;
I can not copy all the tables that create the view definition. Some of them contain sensitive data.
I am sure I missing something basic here...
Ideas?
In MySQL, a view doesn't store anything. It's more like an alias or a macro. It just passes the query logic through to underlying base tables.
You need the underlying base tables to exist on the same MySQL instance where you create the view, and the base tables must remain existing on that same MySQL instance while you query the view.
If you only want to copy the contents of a view, so you don't copy the other sensitive data that is not selected by the view, you would have to create a base table to copy the data:
mysql> CREATE TABLE myview_base AS SELECT * FROM myview;
Then you can do a logical dump of that copy table:
shell > mysqldump --single-transaction mydatabase myview_base > myview_base.sql
Then restore that dump file to your data warehouse as you would any other SQL dump file.
Another possible strategy:
SELECT * FROM myview INTO OUTFILE 'filename.csv';
This dumps the result of an SQL query to a file. See https://dev.mysql.com/doc/refman/8.0/en/select-into.html
The file will be created on the database server, so if you don't have shell access to the server, you won't be able to retrieve the file.
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.
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