{"id":1584,"date":"2026-01-17T22:16:02","date_gmt":"2026-01-17T22:16:02","guid":{"rendered":"https:\/\/www.woodcentral.com\/-\/peter\/?p=1584"},"modified":"2026-05-24T11:28:10","modified_gmt":"2026-05-24T11:28:10","slug":"importing-an-sql-dump-to-a-remote-server","status":"publish","type":"post","link":"https:\/\/www.woodcentral.com\/-\/peter\/importing-an-sql-dump-to-a-remote-server\/","title":{"rendered":"Importing an SQL dump to a remote server"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Below is the standard, reliable command-line approach used by system administrators to import a MariaDB (or MySQL-compatible) SQL dump from a local Linux machine into a <strong>remote<\/strong> MariaDB server.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Method 1: Import directly over the network (no manual upload)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This is the simplest and most common approach.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Basic syntax<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -h remote_host -u db_user -p db_name &lt; dump.sql\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -h db.example.com -u myuser -p mydatabase &lt; backup.sql\n<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>-h remote_host<\/code> \u2014 hostname or IP of the remote server<\/li>\n\n\n\n<li><code>-u db_user<\/code> \u2014 database username<\/li>\n\n\n\n<li><code>-p<\/code> \u2014 prompts for password<\/li>\n\n\n\n<li><code>db_name<\/code> \u2014 target database (must already exist)<\/li>\n\n\n\n<li><code>dump.sql<\/code> \u2014 SQL file on your <strong>local<\/strong> machine<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The SQL file is streamed over the network directly into MariaDB.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Method 2: Specify port or socket (if non-standard)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If the remote server uses a non-default port:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -h db.example.com -P 3307 -u myuser -p mydatabase &lt; backup.sql\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Default port is <code>3306<\/code>.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Method 3: Using compression (recommended for large dumps)<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">For large SQL files, compressing during transfer is significantly faster.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gzip -c dump.sql | mysql -h db.example.com -u myuser -p mydatabase\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Or if the file is already compressed:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gunzip &lt; dump.sql.gz | mysql -h db.example.com -u myuser -p mydatabase\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Method 4: Import via SSH on the remote server<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If the database does <strong>not<\/strong> accept remote connections, you can pipe the file through SSH:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>cat dump.sql | ssh user@remote_server \\\n  \"mysql -u db_user -p db_name\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">You will be prompted for:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SSH password (or key)<\/li>\n\n\n\n<li>MariaDB password (on the remote server)<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Compressed version:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>gzip -c dump.sql | ssh user@remote_server \\\n  \"gunzip | mysql -u db_user -p db_name\"\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">This is common on shared hosting or locked-down servers.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Method 5: Upload first, then import (classic approach)<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Upload the file:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>scp dump.sql user@remote_server:\/home\/user\/\n<\/code><\/pre>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li>SSH into the server:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>ssh user@remote_server\n<\/code><\/pre>\n\n\n\n<ol start=\"3\" class=\"wp-block-list\">\n<li>Import:<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -u db_user -p db_name &lt; dump.sql\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Common issues and solutions<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u201cAccess denied for user \u2026\u201d<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ensure the user has permission from your IP:<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>GRANT ALL PRIVILEGES ON db_name.* TO 'user'@'your_ip';\nFLUSH PRIVILEGES;\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u201cUnknown database\u201d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create it first:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -h remote_host -u user -p -e \"CREATE DATABASE db_name;\"\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u201cMySQL server has gone away\u201d<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use larger packet size:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql --max_allowed_packet=1G -h remote_host -u user -p db_name &lt; dump.sql\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Best practice checklist<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Confirm the database exists<\/li>\n\n\n\n<li>Confirm user has remote access<\/li>\n\n\n\n<li>Use compression for large dumps<\/li>\n\n\n\n<li>Avoid <code>--force<\/code> unless you want to ignore errors<\/li>\n\n\n\n<li>Test with a small dump first<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Below is the standard, reliable command-line approach used by system administrators to import a MariaDB (or MySQL-compatible) SQL dump from a local Linux machine into a remote MariaDB server. Method 1: Import directly over the network (no manual upload) This is the simplest and most common approach. Basic syntax Example The SQL file is streamed &#8230; <a title=\"Importing an SQL dump to a remote server\" class=\"read-more\" href=\"https:\/\/www.woodcentral.com\/-\/peter\/importing-an-sql-dump-to-a-remote-server\/\" aria-label=\"Read more about Importing an SQL dump to a remote server\">Read more<\/a><\/p>\n","protected":false},"author":7,"featured_media":1586,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-1584","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/posts\/1584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/comments?post=1584"}],"version-history":[{"count":0,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/posts\/1584\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/media\/1586"}],"wp:attachment":[{"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/media?parent=1584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/categories?post=1584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.woodcentral.com\/-\/peter\/wp-json\/wp\/v2\/tags?post=1584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}