• About Us
  • Privacy & Policy
HowTo's
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
  • Home
  • Commands
  • Linux
  • SCM
  • Git
  • Database
  • MySQL
  • Kubernetes
  • Docker
No Result
View All Result
HowTo's
No Result
View All Result
Home Database

Directing Output to File in mysqldump

June 22, 2024
in Database, Database Commands Examples, Database Commands Tutorial, Database Tutorial, MySQL, MySQL Commands, MySQL Commands Examples, MySQL Tutorial
A A
0
11
SHARES
104
VIEWS
Share on FacebookShare on Twitter

When using mysqldump to backup MySQL databases, the -r or --result-file=name option is essential for directing the output to a file. This option allows you to specify the file name where the SQL dump will be saved, ensuring you have a reliable backup of your database.

Here are several examples demonstrating the use of -r option with mysqldump:

Example 1: Dumping a single database into a file named backup.sql:

mysqldump -r backup.sql mydatabase

This command exports the database mydatabase into a file called backup.sql. To verify its execution, check if backup.sql exists in the current directory.

Example 2: Dumping multiple databases into a single file named alldatabases.sql:

mysqldump -r alldatabases.sql --databases db1 db2 db3

Here, databases db1, db2, and db3 are exported into a single file named alldatabases.sql. Verify by checking the existence of alldatabases.sql.

Example 3: Dumping all databases on the server into a file named alldatabases.sql:

mysqldump -r alldatabases.sql --all-databases

This command exports all databases on the MySQL server into alldatabases.sql. To verify, confirm that alldatabases.sql is created and contains the expected SQL dump.

Example 4: Dumping a specific table from a database into a file named table_backup.sql:

mysqldump -r table_backup.sql mydatabase mytable

Here, mytable from database mydatabase is exported into table_backup.sql. Check if table_backup.sql exists after execution.

Example 5: Dumping with extended inserts to improve insert performance:

mysqldump -r backup.sql --extended-insert mydatabase

This command includes extended inserts in backup.sql for better performance during data restoration. Verify by examining the content of backup.sql.

Example 6: Dumping with complete inserts to ensure compatibility with older MySQL versions:

mysqldump -r backup.sql --complete-insert mydatabase

This exports mydatabase with complete insert statements into backup.sql. Ensure backup.sql is created and contains the expected SQL statements.

Example 7: Dumping a database with additional options like disabling foreign key checks:

mysqldump -r backup.sql --skip-add-drop-table --skip-disable-keys mydatabase

Here, the command exports mydatabase into backup.sql while skipping certain table operations and key checks. Confirm the contents of backup.sql post-execution.

Example 8: Dumping a database while specifying a custom delimiter:

mysqldump -r backup.sql --hex-blob --routines --triggers --events --delimiter="//" mydatabase

This command exports mydatabase with specific options like hex-blob support and routines/triggers/events into backup.sql using a custom delimiter “//”. Verify the generated file and its contents.

Example 9: Dumping a database with gzip compression:

mysqldump -r backup.sql --single-transaction --quick --compress mydatabase | gzip > backup.sql.gz

This command compresses the SQL dump of mydatabase using gzip and saves it as backup.sql.gz. Check for the existence and integrity of backup.sql.gz.

Example 10: Dumping a database while excluding certain tables:

mysqldump -r backup.sql --ignore-table=mydatabase.table1 --ignore-table=mydatabase.table2 mydatabase

Here, tables table1 and table2 are excluded from the dump of mydatabase, saved into backup.sql. Verify the resulting file to ensure tables are correctly excluded.

Also check similar articles.

Using REPLACE INTO Instead of INSERT INTO in mysqldump
Quoting Table and Column Names in mysqldump Output
Dumping Quickly without Buffering in mysqldump
Setting Connection Protocol in mysqldump
Connecting to MySQL Port in mysqldump

Tags: DatabaseDatabase Commands ExamplesDatabase Commands TutorialDatabase TutorialMySQLMySQL CommandsMySQL Commands ExamplesMySQL Tutorial
Previous Post

Using REPLACE INTO Instead of INSERT INTO in mysqldump

Next Post

Dumping Routines (Functions and Procedures) with mysqldump

Related You may like!

howto

Overriding –databases Option in mysqldump

June 22, 2024
howto

Creating Tab-Separated Output Files with mysqldump

June 22, 2024

Handling Failed SSL Session Data Reuse in mysqldump

June 22, 2024

Setting SSL Session Data File in mysqldump

June 22, 2024

Setting TLS 1.3 Cipher in mysqldump

June 22, 2024

Configuring SSL FIPS Mode in mysqldump (OpenSSL Only)

June 22, 2024
Next Post
howto

Dumping Routines (Functions and Procedures) with mysqldump

howto

Setting Character Set in mysqldump Output

howto

Adding GTID_PURGED to mysqldump Output

Discussion about this post

Latest Updated

howto

How to Use -iname for Case-Insensitive Filename Searches in find

August 21, 2024
howto

Search for Files with Case-Insensitive Pattern Matching Using -ilname in find

August 21, 2024
howto

Find Files by Group Name with -group in find Command

August 21, 2024
howto

Locate Files by Group ID Using -gid in find Command

August 21, 2024
howto

How to Search for Filesystems with -fstype in find Command

August 21, 2024

Trending in Week

  • howto

    Using BTRFS Subvolume for User Home Directory in Linux

    22 shares
    Share 9 Tweet 6
  • Downloading Docker Images from a Registry

    13 shares
    Share 5 Tweet 3
  • Configuring SSL Connection Mode in mysqldump

    17 shares
    Share 7 Tweet 4
  • Omit Tablespace Information in mysqldump Output

    13 shares
    Share 5 Tweet 3
  • Setting MySQL Dump Compatibility Mode

    18 shares
    Share 7 Tweet 5
  • Setting Network Buffer Length in mysqldump

    13 shares
    Share 5 Tweet 3
  • Logging out from Docker Registries

    13 shares
    Share 5 Tweet 3
  • Scheduling Nodes in Kubernetes with kubectl uncordon

    12 shares
    Share 5 Tweet 3
  • Managing Default User Creation Settings in Linux

    15 shares
    Share 6 Tweet 4
  • Using Extended INSERT Syntax in mysqldump

    12 shares
    Share 5 Tweet 3
  • About Us
  • Privacy & Policy

© 2024 All Rights Reserved. Howto.swebtools.com.

No Result
View All Result

© 2024 All Rights Reserved. Howto.swebtools.com.