Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a small or moderate local MySQL database, use mysqldump to write a logical SQL backup, then use the mysql client to restore it. A basic one-database export and import look like this:

mysqldump db_name > backup-file.sql
mysql db_name < backup-file.sql

Replace db_name with the database name and choose a safe path for the backup. Before importing, check that the client is connecting to the intended server and database: the import runs the SQL statements in that file against the target you specify.

What these commands back up—and what they do not

mysqldump creates a logical backup: it asks the server for database object definitions and table contents, then writes SQL statements that can reproduce them. The result is portable and inspectable, and the utility can work at server, database, or table scope. It does not include MySQL server configuration, log files, or other files outside the logical database contents. MySQL 8.0 Reference Manual: mysqldump · MySQL Reference Manual: Backup and Recovery Types

How do I export a MySQL database in Terminal?

Export one database

  1. Open Terminal and make sure the MySQL server is running and you can authenticate with an account that can read the database.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    #1 Best Overall
    Sale
    Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
    • Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
    • Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
    • To get set up, connect the portable hard drive to a computer for automatic recognition no software required
    • This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
    • The available storage capacity may vary.
  2. Choose where to put the dump. The command below creates backup-file.sql in Terminal’s current working directory; use an absolute path if you want a specific location.

  3. Run the export, replacing db_name and the destination filename:

    mysqldump db_name > backup-file.sql

    To save to a chosen folder, for example:

    mysqldump db_name > ~/Documents/db_name-backup.sql
  4. Check the command’s exit status and confirm the file exists and is nonempty. A successful command and a nonempty file are useful checks, but neither proves that the dump can be restored.

The simple example relies on the client’s configured connection and authentication. If your local server needs an explicit host, port, or account, supply the appropriate client options for your installation. Avoid putting a password directly in the command, where it may be saved in shell history. MySQL 8.0 Reference Manual: mysqldump

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Sale
YOTUO 500GB External Hard Drive, Portable Storage Expansion HDD, USB 3.0 & USB-C for PC, Mac, Desktop, Laptop, Smartphone, PS4, Xbox One, Xbox 360, Office & Game Black
  • 【Versatile Storage Expansion – For Gaming, Work & Everyday Use】 Running out of space on your PS5 or Xbox Series X/S? This external hard drive lets you store and play PS4 / Xbox One games directly, instantly freeing up your console’s internal storage for next‑gen titles. At the same time, it handles work file backups, media libraries, and cross‑device data transfers with ease. One drive, all your needs. *(Note: PS5 / Xbox Series X|S games cannot be run or stored directly from the external hard drive. However, by offloading your PS4 / Xbox One games, you can free up valuable space for newer titles.)*
  • 【Patented Silicone Sleeve – Data Protection You Can Count On】 Worried about drops? We’ve got you covered. The patented built‑in silicone sleeve acts like a shock‑absorbing armor, cushioning your drive against bumps and falls. Whether it’s important work documents, precious family photos, or hard‑earned game saves, your data deserves this level of protection.
  • 【Plug & Play, Compatible with Computers & Consoles】 No complicated setup—just plug in and go. Works seamlessly with Windows, Mac, and Linux computers, as well as PS4, PS5, Xbox One, and Xbox Series X/S. Process files at the office, back up data at home, or enjoy gaming in your downtime—one drive handles all your devices, simply and hassle‑free.
  • 【USB 3.0 Ultra‑Fast Transfer – No More Waiting】 Tired of watching progress bars crawl? With USB 3.0 speeds up to 5Gbps, large files transfer in seconds. Whether you’re moving work documents, transferring hundreds of gigs of games, or backing up a year’s worth of photos, you get more done in less time.
  • 【Sleek, Lightweight, and Ready to Go】 Weighing just 0.16 kg—lighter than a can of soda—this compact drive features a stylish mirror‑and‑frosted finish. Toss it in your bag and go, whether you’re heading to the office, visiting a friend for a gaming session, or giving a presentation on the road.

Export every database

The one-database command does not export the whole server. To dump all databases, MySQL documents this separate command:

mysqldump --all-databases > all_databases.sql

Keep the scope in mind when selecting the output filename and storage location: an all-databases dump may contain much more data than a single-database export. MySQL 8.0 Reference Manual: mysqldump

Where is mysqldump on macOS?

There is no single executable path that applies to every Mac installation. MySQL’s native macOS package installer and compressed TAR archive installation can place command-line utilities differently. Use the mysqldump and mysql clients supplied by your MySQL installation, and resolve their executable location or update your shell’s PATH if Terminal reports command not found. The macOS installation documentation also covers managing the server through its launch daemon; if the server is stopped, start it using the method appropriate to your installation before connecting. MySQL 8.0: Installing MySQL on macOS

How do I restore a MySQL database from a .sql file?

Restore into an existing database

  1. Confirm the server connection and the exact database name that should receive the data. Importing into the wrong target can change data there.

    Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
    Rank #3
    YOTUO 1TB External Hard Drive, Portable Storage Expansion HDD, USB 3.0 & USB-C for PC, Mac, Desktop, Laptop, Smartphone, PS4, Xbox One, Xbox 360, Office & Game, Black
    • 【Versatile Storage Expansion – For Gaming, Work & Everyday Use】 Running out of space on your PS5 or Xbox Series X/S? This external hard drive lets you store and play PS4 / Xbox One games directly, instantly freeing up your console’s internal storage for next‑gen titles. At the same time, it handles work file backups, media libraries, and cross‑device data transfers with ease. One drive, all your needs. *(Note: PS5 / Xbox Series X|S games cannot be run or stored directly from the external hard drive. However, by offloading your PS4 / Xbox One games, you can free up valuable space for newer titles.)*
    • 【Patented Silicone Sleeve – Data Protection You Can Count On】 Worried about drops? We’ve got you covered. The patented built‑in silicone sleeve acts like a shock‑absorbing armor, cushioning your drive against bumps and falls. Whether it’s important work documents, precious family photos, or hard‑earned game saves, your data deserves this level of protection.
    • 【Plug & Play, Compatible with Computers & Consoles】 No complicated setup—just plug in and go. Works seamlessly with Windows, Mac, and Linux computers, as well as PS4, PS5, Xbox One, and Xbox Series X/S. Process files at the office, back up data at home, or enjoy gaming in your downtime—one drive handles all your devices, simply and hassle‑free.
    • 【USB 3.0 Ultra‑Fast Transfer – No More Waiting】 Tired of watching progress bars crawl? With USB 3.0 speeds up to 5Gbps, large files transfer in seconds. Whether you’re moving work documents, transferring hundreds of gigs of games, or backing up a year’s worth of photos, you get more done in less time.
    • 【Sleek, Lightweight, and Ready to Go】 Weighing just 0.16 kg—lighter than a can of soda—this compact drive features a stylish mirror‑and‑frosted finish. Toss it in your bag and go, whether you’re heading to the office, visiting a friend for a gaming session, or giving a presentation on the road.
  2. Run the MySQL client with the target database name and redirect the dump file into it:

    mysql db_name < backup-file.sql

    If the file is elsewhere, provide its full path, such as mysql db_name < ~/Documents/db_name-backup.sql.

  3. Review the command’s result and inspect the restored database for the tables and rows you expect. For a backup you rely on, first test the import into a separate database rather than overwriting the live target.

Restore when the target database does not exist

Create the destination deliberately before running the import, using an account and database-creation procedure appropriate to your local server. Then run the same mysql target_database < backup-file.sql pattern against that database. The MySQL manual documents loading SQL dumps with the mysql client; the exact database-creation and authentication commands depend on the server version and account setup. MySQL 8.0 Reference Manual: mysqldump

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
WD 5TB My Passport Ultra for Mac Silver, Portable External Hard Drive, backup software with defense against ransomware, and password protection, USB-C and USB 3.1 - WDBPMV0050BSL-WESN
  • USB-C and USB 3.1 compatible.Specific uses: Business, personal
  • Innovative style with refined metal cover
  • Password protection with 256-bit AES hardware encryption
  • Formatted for Mac

Keeping a dump consistent while MySQL is running

For InnoDB tables, --single-transaction can produce an online dump without locking all tables for the full duration. It is not a universal consistency guarantee: concurrent schema changes (DDL) and nontransactional tables require care. Check the storage engines and activity of the database before relying on this option. For the documented backup-policy example that combines --single-transaction with --source-data, a brief initial lock is involved; use only options supported by the installed client version. MySQL 8.0 Reference Manual: mysqldump · MySQL Reference Manual: Establishing a Backup Policy

A logical dump is not the same as point-in-time recovery. That recovery approach also depends on binary logs and server configuration; a dump alone does not provide it. MySQL’s backup-policy guidance discusses full dumps and binary-log context. MySQL Reference Manual: Establishing a Backup Policy

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

When a logical dump is not the right backup method

Logical dumps are often convenient for local development because they are easy to move, inspect, and restore across machines. Their trade-off is that restoring replays SQL statements, which can be slow for substantial data volumes. MySQL says mysqldump is not intended as a fast, scalable solution for large datasets.

Physical backups copy underlying data files. MySQL describes them as faster to make and restore, which can suit large, important datasets with tighter recovery needs, but they are less portable and demand correct handling of server state and files. Do not assume that casually copying a live data directory is a consistent backup. Choose a version-appropriate physical-backup method if the dataset size, restore speed, or recovery requirements exceed what a logical dump can reasonably serve. MySQL Reference Manual: Backup and Recovery Types · MySQL 8.0 Reference Manual: mysqldump

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
WD 2TB Elements Portable External Hard Drive for Windows, USB 3.2 Gen 1/USB 3.0 for PC & Mac, Plug and Play Ready - WDBU6Y0020BBK-WESN
  • High capacity in a small enclosure – The small, lightweight design offers up to 6TB* capacity, making WD Elements portable hard drives the ideal companion for consumers on the go.
  • Plug-and-play expandability
  • Vast capacities up to 6TB[1] to store your photos, videos, music, important documents and more
  • SuperSpeed USB 3.2 Gen 1 (5Gbps)

Make the backup useful in a recovery

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.