{"id":1491,"date":"2026-09-03T12:17:04","date_gmt":"2026-09-03T06:47:04","guid":{"rendered":"https:\/\/cpanelfree.com\/blog\/how-to-export-import-large-mysql-database-command-line\/"},"modified":"2026-09-03T12:31:03","modified_gmt":"2026-09-03T07:01:03","slug":"how-to-export-import-large-mysql-database-command-line","status":"publish","type":"post","link":"https:\/\/cpanelfree.com\/blog\/how-to-export-import-large-mysql-database-command-line\/","title":{"rendered":"How to Export and Import Large MySQL Databases via Command Line (No Timeout)"},"content":{"rendered":"<div style=\"background-color: #f8fafc;border-left: 4px solid #14b8a6;padding: 20px;border-radius: 6px;margin-bottom: 25px\">\n<p style=\"margin: 0;font-size: 16px;color: #1e293b\">\n        <strong>Quick Answer:<\/strong> To export a large MySQL database without locking production tables, execute <code>mysqldump -u username -p --single-transaction --quick dbname &gt; backup.sql<\/code>. To import a large SQL dump without web browser timeout errors, execute <code>mysql -u username -p dbname &lt; backup.sql<\/code> (or pipe through <code>pv backup.sql | mysql -u username -p dbname<\/code> for live progress tracking).\n    <\/p>\n<\/div>\n<h2>Why phpMyAdmin Fails on Large Database Imports<\/h2>\n<p>When databases grow beyond 50 MB, importing through web interfaces (like phpMyAdmin) frequently fails with <code>504 Gateway Timeout<\/code>, <code>413 Request Entity Too Large<\/code>, or <code>Maximum execution time exceeded<\/code> errors due to web server limits (<code>upload_max_filesize<\/code> and <code>max_execution_time<\/code>).<\/p>\n<p>Using the native Linux MySQL command-line client streams data directly into the database engine with dedicated system memory, allowing multi-gigabyte databases to import in seconds.<\/p>\n<h2>Step 1: Exporting with mysqldump (Production Optimized)<\/h2>\n<p>Use optimal flags to prevent table locking and ensure consistent reads on active WooCommerce databases:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\"># Export and compress on the fly to save disk space\nmysqldump -u db_user -p --single-transaction --quick --lock-tables=false db_name | gzip &gt; \/var\/backups\/db_backup.sql.gz<\/pre>\n<h2>Step 2: Importing Large SQL Dumps via Terminal<\/h2>\n<p>Create the target database if it does not already exist:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">mysql -u root -p -e \"CREATE DATABASE target_dbname DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;\"<\/pre>\n<p>Execute the import directly from the compressed archive:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">gunzip &lt; \/var\/backups\/db_backup.sql.gz | mysql -u root -p target_dbname<\/pre>\n<h2>Step 3: Visual Progress Tracking with Pipe Viewer (pv)<\/h2>\n<p>When importing massive 5 GB+ databases, terminal commands display no output until complete. Install <code>pv<\/code> (Pipe Viewer) to view live progress bars, transfer speeds, and ETA:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">sudo apt install pv -y\n\n# Monitor real-time import progress\npv db_backup.sql | mysql -u root -p target_dbname<\/pre>\n<h2>Speeding Up Large Imports by Temporarily Disabling Foreign Key Checks<\/h2>\n<p>If importing millions of rows with complex relational foreign keys, temporarily disable index checks during import to speed up processing by <strong>5x<\/strong>:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">mysql -u root -p target_dbname -e \"SET FOREIGN_KEY_CHECKS=0; SOURCE \/path\/to\/backup.sql; SET FOREIGN_KEY_CHECKS=1;\"<\/pre>\n<h2>Tuning MySQL Server Parameters for High-Speed Large Imports<\/h2>\n<p>When restoring massive multi-gigabyte SQL database archives on a Linux VPS, temporarily increase these MySQL engine memory buffers in <code>\/etc\/mysql\/my.cnf<\/code> to prevent buffer exhaustion and speed up data ingestion by up to <strong>10x<\/strong>:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">[mysqld]\n# Temporary import buffer optimization\nmax_allowed_packet = 1024M\nnet_buffer_length = 1048576\ninnodb_buffer_pool_size = 4G\ninnodb_log_buffer_size = 512M\ninnodb_write_io_capacity = 2000\ninnodb_flush_log_at_trx_commit = 0<\/pre>\n<p><strong>Note:<\/strong> Setting <code>innodb_flush_log_at_trx_commit = 0<\/code> tells MySQL to flush redo logs once per second rather than on every single INSERT transaction, slashing disk write overhead during bulk data restoration.<\/p>\n<h2>Handling MySQL 8.0 Default Collation Conflicts (utf8mb4_0900_ai_ci)<\/h2>\n<p>If you export a database from a newer MySQL 8.0 server and attempt to import it into a MariaDB 10.11 or older MySQL 5.7 host, you will encounter the error: <code>Unknown collation: 'utf8mb4_0900_ai_ci'<\/code>. Clean the collation using a <code>sed<\/code> stream editor replacement:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">sed -i 's\/utf8mb4_0900_ai_ci\/utf8mb4_unicode_ci\/g' db_backup.sql\nsed -i 's\/utf8mb4_0900_as_cs\/utf8mb4_unicode_ci\/g' db_backup.sql<\/pre>\n<h2>Automating MySQL Backups and Remote Cloud Synchronization via Cron<\/h2>\n<p>Combine command-line database dumps with automated cloud synchronization to establish an offsite disaster recovery workflow:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">#!\/bin\/bash\n# Automated MySQL Backup &amp; Cloud Upload Script\nTIMESTAMP=$(date +\"%Y%m%d_%H%M%S\")\nBACKUP_FILE=\"\/var\/backups\/mysql\/db_${TIMESTAMP}.sql.gz\"\n\n# Dump and compress database\nmysqldump -u root -p'YourPassword' --single-transaction --quick --all-databases | gzip &gt; $BACKUP_FILE\n\n# Sync to S3 storage via Rclone\nrclone copy $BACKUP_FILE cloudstorage:my-database-backups\/daily\/\n\n# Clean local backups older than 7 days\nfind \/var\/backups\/mysql\/ -type f -mtime +7 -name \"*.sql.gz\" -delete<\/pre>\n<h2>Repairing and Optimizing Corrupted Tables with mysqlcheck<\/h2>\n<p>If an unexpected power outage or server reboot causes database corruption, repair and optimize all tables across all databases in a single CLI command:<\/p>\n<pre style=\"background-color: #1e293b;color: #38bdf8;padding: 14px;border-radius: 6px;font-size: 13px\">mysqlcheck -u root -p --auto-repair --check --optimize --all-databases<\/pre>\n<div style=\"background-color: #f8fafc;border: 1px solid #e2e8f0;border-left: 4px solid #0ea5e9;padding: 20px;border-radius: 8px;margin: 30px 0\">\n<h3 style=\"margin-top: 0;color: #0f172a;font-size: 18px;display: flex;align-items: center\">\n        <span style=\"margin-right: 8px\">\ud83d\udd17<\/span> Recommended Related Technical Guides:<br \/>\n    <\/h3>\n<ul style=\"margin: 10px 0 0 0;padding-left: 20px;line-height: 1.8\">\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-setup-free-cloudflare-cdn-dns-hosting\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Set Up Free Cloudflare CDN &amp; DNS on Any Web Hosting<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/dns-a-record-vs-cname-vs-alias-guide\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">DNS A Record vs CNAME vs ALIAS Explained<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/how-to-fix-dns-probe-finished-nxdomain-error\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">How to Fix DNS_PROBE_FINISHED_NXDOMAIN Error<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/blog\/best-free-web-hosting-2026\/\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">Top 10 Best Free Web Hosting Services<\/a><\/li>\n<li><a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"color: #0284c7;text-decoration: none;font-weight: 600\">Explore $0 Free cPanel Web Hosting Plans<\/a><\/li>\n<\/ul>\n<\/div>\n<div style=\"background: linear-gradient(135deg, #0f172a 0%, #1e293b 100%);border: 1px solid #334155;border-radius: 12px;padding: 25px;margin: 30px 0;text-align: center\">\n<h3 style=\"color: #38bdf8;margin-top: 0;font-size: 20px\">High-Capacity Databases on CpanelFree<\/h3>\n<p style=\"color: #94a3b8;font-size: 14px;line-height: 1.6;max-width: 600px;margin: 0 auto 15px\">\n        Enjoy unlimited MySQL databases, phpMyAdmin management, and high-speed NVMe storage at 100% zero cost on <strong>CpanelFree<\/strong>.\n    <\/p>\n<p>    <a href=\"https:\/\/cpanelfree.com\/#plans\" style=\"display: inline-block;background-color: #14b8a6;color: #ffffff;padding: 10px 22px;border-radius: 6px;text-decoration: none;font-weight: bold;font-size: 14px\">Get Free Web Hosting<\/a>\n<\/div>\n<h2>Frequently Asked Questions<\/h2>\n<div style=\"border-bottom: 1px solid #e2e8f0;padding: 12px 0\">\n<h4 style=\"margin: 0 0 8px 0;color: #1e293b\">How can I export only specific tables from a database?<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">Specify table names after the database name: <code>mysqldump -u root -p dbname wp_posts wp_postmeta &gt; content_only.sql<\/code>.<\/p>\n<\/div>\n<h2>Optimizing MySQL my.cnf Buffer Allocation for Large Database Dumps<\/h2>\n<p>When importing multi-gigabyte SQL files containing millions of rows, increasing <code>innodb_buffer_pool_size<\/code> to 70% of available RAM prevents the MySQL storage engine from paging data to disk, completing complex restorations in minutes rather than hours.<\/p>\n<div style=\"border-bottom: 1px solid #e2e8f0;padding: 12px 0\">\n<h4 style=\"margin: 0 0 8px 0;color: #1e293b\">How can I export a single database table without locking the rest of the database?<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">Use the command: <code>mysqldump -u root -p --single-transaction --quick dbname specific_table_name &gt; table_dump.sql<\/code>.<\/p>\n<\/div>\n<p>Executing database imports and exports via native Linux CLI commands bypasses PHP timeout barriers, enabling developers to restore enterprise-scale MySQL databases safely in seconds.<\/p>\n<div style=\"background-color: #f1f5f9;padding: 15px;border-radius: 8px;margin: 20px 0\">\n<h4 style=\"margin-top: 0;color: #1e293b\">Pro Sysadmin Tip: Increasing max_allowed_packet for Bloated Blobs<\/h4>\n<p style=\"margin: 0;color: #475569;font-size: 14px\">If your database contains high-resolution image blobs or massive page builder JSON layouts in the wp_postmeta table, add <code>--max_allowed_packet=1G<\/code> directly to your mysql import command line to prevent packet truncated errors.<\/p>\n<\/div>\n<p>Finally, always test database restoration in a staging environment to verify data integrity before running production database cutovers.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Quick Answer: To export a large MySQL database without locking production tables, execute mysqldump -u username -p &#8211;single-transaction &#8211;quick dbname &gt; backup.sql. To import a large SQL dump without web browser timeout errors, execute mysql -u username -p dbname &lt; backup.sql (or pipe through pv backup.sql | mysql -u username -p dbname for live progress [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1490,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[51],"tags":[],"class_list":["post-1491","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials"],"_links":{"self":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/comments?post=1491"}],"version-history":[{"count":7,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1491\/revisions"}],"predecessor-version":[{"id":1538,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/posts\/1491\/revisions\/1538"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media\/1490"}],"wp:attachment":[{"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/media?parent=1491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/categories?post=1491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cpanelfree.com\/blog\/wp-json\/wp\/v2\/tags?post=1491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}