{"id":18433,"date":"2026-09-30T07:34:05","date_gmt":"2026-09-30T04:34:05","guid":{"rendered":"https:\/\/www.hyyat.com\/knowledgebase\/import-mysql-database-ssh\/"},"modified":"2026-11-22T18:53:08","modified_gmt":"2026-11-22T15:53:08","password":"","slug":"import-mysql-database-ssh","status":"publish","type":"docs","link":"https:\/\/www.hyyat.com\/en\/knowledgebase\/import-mysql-database-ssh\/","title":{"rendered":"Importing and Exporting a Database from the Command Line: mysql and mysqldump for Large Files"},"content":{"rendered":"<div class=\"hkb\" dir=\"ltr\">\n<div class=\"hkb-tldr\"><b>The two commands<\/b>Export: <code>mysqldump db_name &gt; file.sql<\/code>. Import into an existing database: <code>mysql db_name &lt; file.sql<\/code>. Compressed: <code>zcat file.sql.gz | mysql db_name<\/code>. This route is not bound by phpMyAdmin\u2019s upload limits.<\/div>\n<div class=\"hy-vid\"><div style=\"width: 1280px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-18433-1\" width=\"1280\" height=\"720\" poster=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hyyat-srv-sqlimport-en.jpg\" preload=\"none\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hyyat-srv-sqlimport-en.mp4?_=1\" \/><a href=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hyyat-srv-sqlimport-en.mp4\">https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hyyat-srv-sqlimport-en.mp4<\/a><\/video><\/div><\/div>\n<div class=\"hkb-note\"><b>The idea:<\/b> An SQL file is text holding the commands that rebuild tables and data. Exporting writes those commands to a file; importing runs them on another database. Over SSH the only size limit is disk space.<\/div>\n<figure class=\"hkb-fig\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.hyyat.com\/zasogooh\/2026\/11\/hkb-sv-t-sqlimp.webp\" alt=\"Commands to export, import and check a database from the command line\" width=\"800\" height=\"451\" loading=\"lazy\" \/><\/figure>\n<h2>Exporting (a backup)<\/h2>\n<pre class=\"hkb-code\">mysqldump example_wp &gt; \/home\/example\/example_wp.sql\nmysqldump example_wp | gzip &gt; \/home\/example\/example_wp.sql.gz   # compressed\nmysqldump --single-transaction example_wp &gt; db.sql            # without locking InnoDB tables<\/pre>\n<p><code>--single-transaction<\/code> helps for a live site: it takes a consistent copy without stopping writes to InnoDB tables.<\/p>\n<h2>Importing<\/h2>\n<ol class=\"hkb-steps\">\n<li><b>Create the database first<\/b> on a cPanel server, create it in the account\u2019s cPanel with its user so it shows in the interface.<\/li>\n<li><b>Upload the file<\/b> to the account\u2019s home over SFTP, not into public_html.<\/li>\n<li><b>Run the import<\/b> <code>mysql example_wp &lt; \/home\/example\/example_wp.sql<\/code>.<\/li>\n<li><b>Check<\/b> <code>mysqlcheck example_wp<\/code>, then open the site.<\/li>\n<li><b>Delete the file<\/b> the SQL file holds the whole site\u2019s data, so do not leave it on the server.<\/li>\n<\/ol>\n<h2>Import problems<\/h2>\n<div class=\"hkb-tbl\">\n<table>\n<thead>\n<tr>\n<th>Message<\/th>\n<th>Fix<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><code>MySQL server has gone away<\/code><\/td>\n<td>Raise max_allowed_packet in Edit Database Configuration in WHM<\/td>\n<\/tr>\n<tr>\n<td><code>Unknown collation: utf8mb4_0900_ai_ci<\/code><\/td>\n<td>The file came from MySQL 8 and the server runs MariaDB. Replace the collation with utf8mb4_unicode_ci in the file before importing<\/td>\n<\/tr>\n<tr>\n<td>Arabic text shows as odd symbols<\/td>\n<td>Set the encoding: <code>mysql --default-character-set=utf8mb4 db &lt; file.sql<\/code><\/td>\n<\/tr>\n<tr>\n<td><code>Table already exists<\/code><\/td>\n<td>The database is not empty. Import into a new one, or drop the tables first after a backup<\/td>\n<\/tr>\n<tr>\n<td><code>Access denied; you need SUPER privilege<\/code><\/td>\n<td>The file has a DEFINER for a missing user. Remove the DEFINER lines or export without them<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<div class=\"hkb-note warn\">Importing over a live site\u2019s database replaces its data. Take a mysqldump copy before importing over it.<\/div>\n<p>If the file is small and you prefer a screen, phpMyAdmin is covered in <a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/import-export-mysql-database-phpmyadmin\/\">import and export with phpMyAdmin<\/a>, and its upload limits in <a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/increase-phpmyadmin-upload-size-whm\/\">raising the import size<\/a>.<\/p>\n<h2>Moving a database directly between servers<\/h2>\n<p>If the two servers can reach each other over SSH, you can move the database with no intermediate file:<\/p>\n<pre class=\"hkb-code\">mysqldump example_wp | ssh root@203.0.113.20 &quot;mysql example_wp&quot;<\/pre>\n<p>It exports on this server and imports on the other in one step. Create the empty database on the target first. On a slow link, add compression: <code>mysqldump example_wp | gzip | ssh root@... \"gunzip | mysql example_wp\"<\/code>.<\/p>\n<h2>Import and export questions<\/h2>\n<div class=\"hkb-faq\">\n<details>\n<summary>How long does a large import take?<\/summary>\n<p>It depends on size, indexes and disk speed. Run it inside screen so it survives a dropped connection.<\/p>\n<\/details>\n<details>\n<summary>Can I export every database at once?<\/summary>\n<p>Yes, mysqldump &#8211;all-databases, but one file per database is easier for restoring a single site.<\/p>\n<\/details>\n<details>\n<summary>Is a mysqldump enough as a site backup?<\/summary>\n<p>It covers the database only. Files need copying too, or use a full cPanel backup.<\/p>\n<\/details>\n<\/div>\n<div class=\"hkb-rel\"><b>Related guides<\/b><\/p>\n<ul>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/mysql-commands-ssh\/\">Working with MySQL and MariaDB from the Command Line: Logging In, Querying, and Creating a Database and User<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/increase-phpmyadmin-upload-size-whm\/\">Raising the phpMyAdmin Database Import Size on a cPanel Server: The Right Setting in WHM<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/import-export-mysql-database-phpmyadmin\/\">Export and Import a Database with phpMyAdmin in cPanel: Backups and Site Moves<\/a><\/li>\n<li><a href=\"https:\/\/www.hyyat.com\/en\/knowledgebase\/configure-backups-whm\/\">Automatic Backups in WHM (Backup Configuration): Daily, Weekly and an Off-Server Copy<\/a><\/li>\n<\/ul>\n<p><a href=\"https:\/\/www.hyyat.com\/en\/kb\/servers-without-control-panel\/\">All server guides \u2192<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The two commandsExport: mysqldump db_name &gt; file.sql. Import into an existing database: mysql db_name &lt; file.sql. Compressed: zcat file.sql.gz | mysql db_name. This route is not bound by phpMyAdmin\u2019s upload limits. The idea: An SQL file is text holding the commands that rebuild tables and data. Exporting writes those commands to a file; importing runs [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":21313,"comment_status":"open","ping_status":"closed","template":"","meta":{"inline_featured_image":false,"_templately_pack_id":"","_templately_imported_at":"","_templately_source":"","_templately_import_session_id":"","footnotes":""},"doc_category":[2733],"doc_tag":[],"class_list":["post-18433","docs","type-docs","status-publish","has-post-thumbnail","hentry","doc_category-servers-without-control-panel"],"year_month":"2026-11","word_count":572,"total_views":0,"reactions":{"happy":0,"normal":0,"sad":0},"author_info":{"name":"ahmed fathy","author_nicename":"ahmed-fathy","author_url":"https:\/\/www.hyyat.com\/en\/author\/ahmed-fathy\/"},"doc_category_info":[{"term_name":"Servers Without a Control Panel","term_url":"https:\/\/www.hyyat.com\/en\/kb\/servers-without-control-panel\/"}],"doc_tag_info":[],"knowledge_base_info":[],"knowledge_base_slug":[],"_links":{"self":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs\/18433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/comments?post=18433"}],"version-history":[{"count":0,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/docs\/18433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/media\/21313"}],"wp:attachment":[{"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/media?parent=18433"}],"wp:term":[{"taxonomy":"doc_category","embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/doc_category?post=18433"},{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/www.hyyat.com\/en\/wp-json\/wp\/v2\/doc_tag?post=18433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}