mysqldump with some tables, not using --skip-table - mysql

To dump a single database I can do:
mysqldump -u root files
To dump a single table I can do:
mysqldump -u root files path
How would I dump two tables combined? Something like:
mysqldump -u root files path&path_updated
Note that I have about 50 tables, only two of which need to be exported, so I don't want to do a --skip-table on this.

Just keep adding table names
mysqldump -u root files path path_updated ...
Check the documentation
http://dev.mysql.com/doc/refman/5.5/en/mysqldump.html

mysqldump databasename table1 table2 (Reference)

Related

Is importing a table from dump will delete my old table data? [duplicate]

Normally, when I backup the database, I run a command like this:
mysqldump -uuser -p -hhost -Ddatabase > C:\TEMP\db_2018-04-05.sql
Inside that file, there are DROP table statements. This is normally fine, but I've modified my localhost to have a different schema than the production database.
If I execute this file, it will blow away the important changes to the database schema on my localhost.
All I need is the INSERT statements. Is there any flag I can pass mysqldump to achieve this?
Include the command for the mysqldump ignore the structure.
mysqldump --no-create-info ...
All you need is add --skip-add-drop-table option when using mysqldump.
$ mysqldump -uuser -p -hhost -Ddatabase --skip-add-drop-table > C:\TEMP\db_2018-04-05.sql
Now no DROP TABLE IF EXISTS in SQL files.
see docs of mysql on --skip-add-drop-table.

How to mysqldump WITHOUT dropping any tables

Normally, when I backup the database, I run a command like this:
mysqldump -uuser -p -hhost -Ddatabase > C:\TEMP\db_2018-04-05.sql
Inside that file, there are DROP table statements. This is normally fine, but I've modified my localhost to have a different schema than the production database.
If I execute this file, it will blow away the important changes to the database schema on my localhost.
All I need is the INSERT statements. Is there any flag I can pass mysqldump to achieve this?
Include the command for the mysqldump ignore the structure.
mysqldump --no-create-info ...
All you need is add --skip-add-drop-table option when using mysqldump.
$ mysqldump -uuser -p -hhost -Ddatabase --skip-add-drop-table > C:\TEMP\db_2018-04-05.sql
Now no DROP TABLE IF EXISTS in SQL files.
see docs of mysql on --skip-add-drop-table.

how to use --no-data for few tables and full data for few tables in single command mysqldump?

I have scenarios like to back up the few tables structures and other few tables structure + contents.
I read about all the options of mysqldump
It says that --no-data will backup all the tables structures only like
mysqldump -h localhost -u root -p wp2 --no-data wp_options wp_users > mydatabase_backup.sql
but I want the same command to perform the both such as few tables only structures and few tables structure + contents.
Is there any possibility to achieve this?
I had to run two different commands
First one structure only tables mysqldump command
mysqldump -h localhost -u root -p wp2 --no-data structure_only_table > mydatabase_backup.sql
Then executed full table backups and >> helped to merge both files.
mysqldump -h localhost -u root -p wp2 full_tables >> mydatabase_backup.sql

Restore MySQL table from backup

I have created backup of a specific table from my database by using the command below.
mysqldump -u root -p db_name table_name > table.sql
Is it possible to restore the specific backup table without affecting the data of the rest of the tables? Which means, whatever data from my backup file for my table will be the only one affected?
The reverse will be:
mysql database_name < database_name.sql
But this is for the whole database. How to do it with table backup alone?
While the answer given by "Pradeep Reddy" is absolutely correct there is another way of doing it as well from inside mysql prompt using the SOURCE command.
mysql> USE database_name;
mysql> SOURCE /my_fullpath_to_backup_folder/table.sql
mysql -u root -p databasename < mytable.sql

generating database with different name from mysqldump backup

The database "db" is backuped in backup.sql. Is there a way to restore database from script with different from "db" name?
thank you in advance!
Sure, when you import it you do this right:
mysql -uuser -ppassword databasename < mydump.sql
You can put anything you want where I wrote databasename - as long as that database actually exists :)
This depends on how you created your MySQL dB dump file
for example, if you do
mysqldump -h localhost -u user mydb -pXXX > mydb.sql
There won't be any CREATE DATABASE statements in your sql dump file. But I think you can only backup one database.
If you create your mysql dump file with --database or --all-databases option
for example
mysqldump -h localhost -u user --database mydb -pXXX > mydb.sql
mysqldump -h localhost -u user --all-databases -pXXX > alldb.sql
then you will see CREATE DATABASE statement in your mysql dump file. If you want a different dB name, you will need to change it before DB restore.
If the name of the database is include the SQL file, I didn't find any other way than modify the SQL file.
My favorite command to do it :
sed -i "s/\`old_db_name\`/\`new_db_name\`/g" my_sql_file.sql
Open up the .sql file and change the database name inside.
You can use a text editor, like Notepad or gedit.