This question was migrated 12 years ago.
I need to take back up of MySQL database,but condition is that back up file should contains only tables that contains data, and there should be an create and drop statements too.
I checked mysqldump manual pages, didn't get options.
If you know the tables that contain data, why do you not simply selectively dump those tables?
mysqldump [options] [db_name [tbl_name ...]]
Related
This question already has answers here:
How to generate entire DDL of an Oracle schema (scriptable)?
(7 answers)
Closed 2 years ago.
I want to create tables from one schema to another. i.e. complete table script.
eg: Let say in schema 'A' tables are present and need to create in schema 'B'.
Can we do this with a scripts as there are lot of tables? or manually is the only option?
Could anyone pls suggests.
Thanks.
Yes it can be done by a script. Below, you will find the example of how to retrieve the DLL of a single Table. Now, using this example, you can create the script in no time.
SELECT DBMS_METADATA.get_ddl ('TABLE', table_name, owner)
FROM all_tables
WHERE owner = 'OWNER'
AND table_name = 'TABLE_NAME';
If you want the script directly, the following Link will provide you with your desired result:
How to generate entire DDL of an Oracle schema (scriptable)?
How to combine several sqlite databases (one table per file) into one big sqlite database containing all the tables. e.g. you have database files: db1.dat, db2.dat, db3.dat.... and you want to create one file dbNew.dat which contains tables from all the db1, db2...
Several similar questions have been asked on various forums. I posted this question (with answer) for a particular reason. When you are dealing with several tables and have indexed many fields there. It causes unnecessary confusion to create index properly into the destination database tables. You may miss 1-2 index and its just annoying. The given method can also deal with large amount of data i.e. when you really have gbs of tables. Following are the steps to do so:
Download sqlite expert: http://www.sqliteexpert.com/download.html
Create a new database dbNew: File-> New Database
Load the 1st sqlite database db1 (containing a single table): File-> Open Database
Click on the 'DDL' option. It gives you a list of commands which are needed to create the particular sqlite table CONTENT.
Copy these commands and select 'SQL' option. Paste the commands there. Change the name of destination table DEST (from default name CONTENT) into whatever you want.
6'Click on 'Execute SQL'. This should give you a copy of the table CONTENT in db1 with the name DEST. The main utility of doing it is that you create all the index also in the DEST table as they were in the CONTENT table.
Now just click and drag the DEST table from the database db1 to the database dbNew.
Now just delete the database db1.
Go back to step 3 and repeat with the another database db2 etc.
Can any one tell me , How can i take database dump using pg_dump without getting specific table records.
If you want a table-wide filter, you can use either --exclude-table=table or --table=table to resp. exclude tables or include only the tables you want.
If you want to "filter out" some records, then you have no direct option to do it. My best advice is to:
dump your full database
restore it as another name (so you now have a copy of your
original DB)
DELETE the records you wish to get rid of
dump the database
This is of course quite rudimentary, and there might be other solutions suitable to your needs. E.g. dump using plain text format then manually edit the dump to remove the rows.
How do I dump single table data from a huge dump file into the database.
If I understand your question correctly - you already have a dump file of many tables and you only need the restore one table (right?).
I think the only way to do that is to actually restore the whole file into a new DB, then copy the data from the new DB to the existing one, OR dump only the table you just restored from the new DB using:
mysqldump -u username -p db_name table_name > dump.sql
And restore it again wherever you need it.
To make things a little quicker and save some disk, you can kill the first restore operation after the desired table was completely restored, so I hope the table name begins with one of the first letters of the alphabet :)
There are some suggestions on how you might do this in the following articles:
http://blog.tsheets.com/2008/tips-tricks/mysql-restoring-a-single-table-from-a-huge-mysqldump-file.html
http://blog.tsheets.com/2008/tips-tricks/extract-a-single-table-from-a-mysqldump-file.html
I found these by searching for "load single table from mysql database dump" on Google: http://www.google.com/search?q=load+single+table+from+mysql=database+dump
Can I programatically(or whichever way works fine) create the backup of a database, with only the tables I want? I have around 100 tables in my database and I want only 10 tables backup(ofcourse all are interdependant). How can I achieve this? And by the way I have a postgresql database.
Of course. pg_dump lets you pass list of tables with parameter -t
To clear some doubts. True, the -t parameter accepts only one pattern. But it's a pattern very similar to regular expression, so if you want to dump tables A, B & C you can do:
pg_dump -t '(A|B|C)'