If you want to take a full backup i.e., all databases, procedures, routines, and events without interrupting any connections:
mysqldump -u [username] -p -A -R -E --triggers --single-transaction > full_backup.sql
-A
For all databases (you can also use--all-databases
)-R
For all routines (stored procedures & triggers)-E
For all events--single-transaction
Without locking the tables i.e., without interrupting any connection (R/W).
If you want to take a backup of only specified database(s):
mysqldump -u [username] -p [database_name] [other_database_name] -R -e --triggers --single-transaction > database_backup.sql
If you want to take a backup of only a specific table in a database:
mysqldump -u [username] -p [database_name] [table_name] > table_backup.sql
If you want to take a backup of the database structure only just add --no-data
to the previous commands:
mysqldump -u [username] –p[password] –-no-data [database_name] > dump_file.sql
mysqldump
has many more options, which are all documented in the mysqldump
documentation or by running man mysqldump
at the command line.