mysql: dump structure+data and only structure in one dump - mysql

With MySQL, I use these commands to dump all db, only the tables structure or only the data.
mysqldump -h localhost -u username -ppwd mydb > dump_all.sql
mysqldump --no-create-db --no-create-info -h localhost -u username -ppwd mydb > dump_only_data.sql
mysqldump --no-data -h localhost -u username -ppwd mydb > dump_only_structure.sql
Is it possible that in one dump command extracting all the tables structure and for some of these tables the data too?

Related

Dump Mysql Table with character "#" in their name

It seems i cannot dump my table (with "#" character) using this command
sudo mysqldump -u root -p --single-transaction --routines --triggers -h 127.0.0.1 my_db "tbl_field_values_259778_hut#002b1" > tbl_field_values_259778_hut#002b1.sql
When i execute command, It shows :
mysqldump: Couldn't find table: "tbl_field_values_259778_hut#002b1"
Unfortunately i dont have permission to rename the table inside mysql command line.
This command is not work either (using escape and quotes)
sudo mysqldump -u root -p --single-transaction --routines --triggers -h 127.0.0.1 my_db "tbl_field_values_259778_hut\#002b1" > tbl_field_values_259778_hut\#002b1.sql
sudo mysqldump -u root -p --single-transaction --routines --triggers -h 127.0.0.1 my_db "tbl_field_values_259778_hut\#002b1" > "tbl_field_values_259778_hut\#002b1.sql"

Ignoring table in mysqldump?

Hi I'm doing a database copy and paste from a master to a slave. However there is a table on the slave that I don't want to be overwritten by the master.
I have been trying out the following bash script which is ran via cron job - but it keeps overwriting the slave table I want to ignore. What am I doing wrong?
#!/bin/bash
#Database login credentials - need to be changed accordingly
dbHost="localhost"
#Master (Staging)
dbMastUser="admin_site"
dbMastName="admin_site_pineapple_master"
#Slave (Live)
dbSlavUser="admin_sync"
dbSlavName="admin_site_pineapple_slave"
dbPass="ExamplePassword"
EXCLUDED_TABLES=(
forms-responses
)
IGNORED_TABLES=''
for TABLE in "${EXCLUDED_TABLES[#]}"
do :
IGNORED_TABLES+=" --ignore-table=${dbMastName}.${TABLE}"
done
#Update the database from the Master to the Slave
mysqldump -h ${dbHost} -u ${dbMastUser} -p${dbPass} ${dbMastName} ${IGNORED_TABLES} | mysql -h ${dbHost} -u ${dbSlavUser} -p${dbPass} ${dbSlavName}
For ignoring tables you must use this syntax
mysqldump -h {hostname} -u {username} -p{password} --ignore-table test.votes test > E:/db_backups/test_1480080906.sql
general syntax
mysqldump -h {hostname} -u {username} -p{password} --ignore-table dbname.tbl_name db_name > E:/db_backups/test_1480080906.sql
Note : we need to set the options to ignore some tables
Thanks
Suman W.
/usr/local/mysql/bin/mysqldump -uroot -p{pwd} --skip-lock-tables --databases f6dms $(mysql -uroot -p{pwd} -Df6dms -Bse "show tables like 'tm_monitor_avg_price_%'"|awk '{print "--ignore-table=f6dms."$1}'|xargs)| gzip > /data/backup/database_f6dms_`date '+%m-%d-%Y'`.sql.gz;

mysqldump exports only one table on other table

I want to dump one table on other server. This is my command:
mysqldump -h xxxx -u xxxx -p xxxx shema_nme table_name >dump.sql
but I had every time the error: couldn't find table xxx
Can you please help me on the syntax?
Dump from remote server follow this
mysqldump -u <db_username> -h <db_host> -p db_name table_name > table_name.sql
Local database dump
mysqldump db_name table_name > table_name.sql
and,Make sure your db_username,db_password and db_host

I can not make DB dump using mysqldump

I am trying to make DB dump using mysqldump like below,
# mysql -u root -p
after i login, i did command like below,
#mysql> mysqldump -u root -p --no-data Dbname > /var/lib/myfolder/MyDB.sql
if i enter then it gives like below,
mysql> mysqldump -u root -p --no-data Dbname > /var/lib/myfolder/MyDB.sql
->
->
->
->
->
I can not do anything than CTR+C. where am i doing silly mistakes?
Issue the command at shell level, not from within mysql, i.e. instead of
# mysql -u root...
type
# mysqldump -u root -p --no-data Dbname > /var/lib/myfolder/MyDB.sql
You are missing the ; at the end of the command. Try it like so:
mysql> mysqldump -u root -p --no-data Dbname > /var/lib/myfolder/MyDB.sql;

how can i take backup of mysql database tables

i want to move mysql database tables which resides in one computer to another computer. how can i create dump file as we created in Oracle ?
i m using exp command but not working.
Use mysqldump.
mysqldump -u <username> -p<password> <db_name> > <filename>.sql
To import, create empty database named <db_name>, thena -
mysql -u <username> -p<password> <db_name> < <filename>.sql
To export all databases -
mysqldump -u <username> -p<password> --all-databases > <filename>.sql
mysqldump -u <username> -p<password> -h <hostname> <dbname> <tablename> > filename.sql
Now you may need to take the dump of just the schema. For example you use a command called like.
mysql> show create table tablename;
this will give you the query that created the table. Now for some reason you need to take schema dump of all the tables inside you database/databases you may use -d option like this
mysqldump -d -u <username> -p<password> -h <hostname> <dbname> > filename.sql
The -d option means "without data".
Now you have full dump without the data and just the schema.