{"id":9434,"date":"2022-04-21T13:35:28","date_gmt":"2022-04-21T17:35:28","guid":{"rendered":"https:\/\/kb.n0c.com\/?post_type=ht_kb&#038;p=9434"},"modified":"2026-08-31T12:11:04","modified_gmt":"2026-08-31T16:11:04","slug":"database-import-export-in-command-line-user-mode","status":"publish","type":"ht_kb","link":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/","title":{"rendered":"How to Import\/Export Database in Command Line (User Mode)"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Introduction<\/h2>\n\n\n\n<p>This article explains how to import\/export database in command line (user mode).<\/p>\n\n\n\n<p>Before explaining the basic principles of this article, it is necessary to make sure that the reader is familiar with certain notions. We will therefore start by defining the terms we will use, sometimes using English translations of words commonly used in computing. At the same time, we will explain the concepts underlying the principles we are dealing with.<\/p>\n\n\n\n<p>Then, using examples from MySQL, we will discuss the concrete application of the concepts taught.<\/p>\n\n\n\n<p>Finally, some references to consult will be proposed.<\/p>\n\n\n\n<p class=\"wp-block-ht-blocks-messages wp-block-hb-message wp-block-hb-message--withicon is-style-info\"><strong><strong>Note :<\/strong>&nbsp;<\/strong>The&nbsp;<a href=\"https:\/\/kb.n0c.com\/en\/glossary\/\">Glossary<\/a>&nbsp;contains explanations on multiple topics and can be consulted to clarify certain terms.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Terminology and Basic Concepts<\/h2>\n\n\n\n<p>It is sometimes necessary to recover all of the data contained in a database, either to make a backup or to switch to another database. The term &#8220;export&#8221; refers precisely to the action of formatting all the information necessary to create a database identical to the first one in an export file, called a dump. The term &#8220;import&#8221; refers to the opposite operation: creating a new database in a DBMS from an export file.<\/p>\n\n\n\n<p>It is important to understand what a command line interface (CLI) is. A CLI is a man-machine interface in which the user interacts with a computer system by entering textual instruction lines to ask the computer to perform operations, which are interpreted by a Shell (as opposed to using a Graphic User Interface, or GUI). Figure 1 shows an example of the instruction lines written in MySQL.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysqldump -h host -u user\n-ppass -rfile database [tables]<\/pre>\n\n\n\n<p class=\"has-small-font-size\"><em><span style=\"color:#818181\" class=\"has-inline-color\">Figure 1 \u2013 Textual instruction lines of a command line interface (MySQL)<\/span><\/em><\/p>\n\n\n\n<p>The diagram in Figure 2 summarizes the basic principle of importing and exporting a database from the command line into a DBMS:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1000\" height=\"426\" src=\"https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1.jpg\" alt=\"importing and exporting a database from the command line into a DBMS\" class=\"wp-image-13931\" srcset=\"https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1.jpg 1000w, https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1-300x128.jpg 300w, https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1-768x327.jpg 768w, https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1-50x21.jpg 50w, https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1-60x26.jpg 60w, https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1-100x43.jpg 100w\" sizes=\"auto, (max-width: 1000px) 100vw, 1000px\" \/><\/a><\/figure><\/div>\n\n\n<p class=\"has-small-font-size\"><em><span style=\"color:#868686\" class=\"has-inline-color\">Figure 2 &#8212; Importing and exporting a database into a DBMS<\/span><\/em><\/p>\n\n\n\n<p>The interpretation of the command line by the Shell can be done in two ways: in Kernel mode or in user mode. In the latter mode, which is of interest to us here &#8211; that of applications in particular &#8211; the executed code does not have direct access to the hardware or to a memory location as is the case in Kernel mode, with all the risks that this entails. On the contrary, in user mode, the code delegates these accesses to the Application Programming Interface (API) of the system.<\/p>\n\n\n\n<p>To summarize what we have seen so far, our goal is to explain the basic principles of formatting in a file (dump) all the information necessary to create a database identical to the original one &#8211; export &#8211; and to create a new database from such a file &#8211; import &#8211; by communicating with the computer by means of textual instructions that do not allow direct access to the hardware or to a location in memory.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Examples of Command Line Usage<\/h2>\n\n\n\n<p>In order to illustrate concretely the principles we have explained so far, we will proceed by example. We will deal with the tools that MySQL offers to export its databases to other DBMS or to import them from the command line.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Complete Export of a MySQL Database<\/h3>\n\n\n\n<p>The main online command for exporting data is called mysql. This command allows you to export an entire database hosted by MySQL. Here is the syntax:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -h host -u user -ppass database &gt; file_dump<\/pre>\n\n\n\n<p>The following notation is also possible:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql --host host --user user\n--passwordpass database &gt; dump_file<\/pre>\n\n\n\n<p>Here is the definition of each term:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em>host<\/em>: name or IP address of the machine on which the database to be exported is installed (localhost by default, i.e. the machine from which the mysql command is launched).<\/li>\n\n\n\n<li><em>user<\/em>: user with which you want to connect (by default, root).<\/li>\n\n\n\n<li><em>password<\/em>: password of the user you want to connect with.<\/li>\n\n\n\n<li><em>database<\/em>: name of the database to export.<\/li>\n\n\n\n<li><em>dump_file<\/em>: name of the file in which the database will be exported.<\/li>\n<\/ul>\n\n\n\n<p>In the following example, the command line is used to export the database named <em>employees<\/em> located on the machine <em>db.company<\/em> and belonging to the user <em>school<\/em> whose password is <em>9a7e<\/em> :<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -h db.company -u school -p9a7e employees &gt; employees.sql<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Partial Export of a MySQL Database with Mysqldump<\/h3>\n\n\n\n<p>Sometimes it is necessary to have the flexibility to export only a part of a database, such as a table or portion of a table, or even to export several databases. Here is the syntax of the mysqldump command designed for this purpose:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysqldump [options] database [tables]<\/pre>\n\n\n\n<p>The options generally used are the following:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysqldump -h host -u user\n-ppass -rfile database [tables]<\/pre>\n\n\n\n<p>In addition to the host, user and pass options defined previously, we notice the file option, which is the name of the file in which the database will be exported.<\/p>\n\n\n\n<p>In this example, the <em>name<\/em> and <em>city<\/em> tables are imported:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -h db.company -u school -p9a7e oemployees.sql employees name city<\/pre>\n\n\n\n<p>It is even possible to use SQL conditions thanks to the -w (where) clause, the command located after being delimited by double or single quotes. Thus:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -h db.company -u school -p9a7e oemployees.sql -w \"id&gt;10\" employees name city<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Importing a MySQL Database<\/h3>\n\n\n\n<p>mysql is also used to import a database. Here is the notation using the &lt; redirection and indicating the dump file containing the SQL statements to import:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql -h host -u user -ppass database &lt; file_dump<\/pre>\n\n\n\n<p>We can also use this notation:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql --host host --user user\n-passwordpass database &lt; file_dump<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">References<\/h2>\n\n\n\n<p>The reader interested in more details can read the following references, which were consulted to develop this text:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/www.commentcamarche.net\/contents\/694-importer-et-exporter-des-donnees-sous-mysql\" target=\"_blank\">https:\/\/www.commentcamarche.net\/contents\/694-importer-et-exporter-des-donnees-sous-mysql<\/a> (in French)<\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/blog.codinghorror.com\/understanding-user-and-kernel-mode\/\" target=\"_blank\">https:\/\/blog.codinghorror.com\/understanding-user-and-kernel-mode\/<\/a><\/li>\n\n\n\n<li><a rel=\"noreferrer noopener\" href=\"https:\/\/technique.arscenic.org\/lamp-linux-apache-mysql-php\/mysql-le-serveur-de-bases-de-donnees\/article\/utiliser-mysql-en-ligne-de-commande\" target=\"_blank\">https:\/\/technique.arscenic.org\/lamp-linux-apache-mysql-php\/mysql-le-serveur-de-bases-de-donnees\/article\/utiliser-mysql-en-ligne-de-commande<\/a> (in French)<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Introduction This article explains how to import\/export database in command line (user mode). Before explaining the basic principles of this article, it is necessary to make sure that the reader is familiar with certain notions. We will therefore start by defining the terms we will use, sometimes using English translations&#8230;<\/p>\n","protected":false},"author":4,"comment_status":"closed","ping_status":"closed","template":"","format":"standard","meta":{"footnotes":""},"ht-kb-category":[164],"ht-kb-tag":[],"class_list":["post-9434","ht_kb","type-ht_kb","status-publish","format-standard","hentry","ht_kb_category-databases"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Import\/Export Database in Command Line (User Mode) - N0C KB<\/title>\n<meta name=\"description\" content=\"This article explains how to import\/export database in command line (user mode).\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Import\/Export Database in Command Line (User Mode) - N0C KB\" \/>\n<meta property=\"og:description\" content=\"This article explains how to import\/export database in command line (user mode).\" \/>\n<meta property=\"og:url\" content=\"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/\" \/>\n<meta property=\"og:site_name\" content=\"N0C KB\" \/>\n<meta property=\"article:modified_time\" content=\"2026-08-31T16:11:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"426\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/database-import-export-in-command-line-user-mode\\\/\",\"url\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/database-import-export-in-command-line-user-mode\\\/\",\"name\":\"How to Import\\\/Export Database in Command Line (User Mode) - N0C KB\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/database-import-export-in-command-line-user-mode\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/database-import-export-in-command-line-user-mode\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/kb.n0c.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Importation_Exportation_EN-1.jpg\",\"datePublished\":\"2022-04-21T17:35:28+00:00\",\"dateModified\":\"2026-08-31T16:11:04+00:00\",\"description\":\"This article explains how to import\\\/export database in command line (user mode).\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/database-import-export-in-command-line-user-mode\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/database-import-export-in-command-line-user-mode\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/database-import-export-in-command-line-user-mode\\\/#primaryimage\",\"url\":\"https:\\\/\\\/kb.n0c.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Importation_Exportation_EN-1.jpg\",\"contentUrl\":\"https:\\\/\\\/kb.n0c.com\\\/wp-content\\\/uploads\\\/2024\\\/01\\\/Importation_Exportation_EN-1.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/database-import-export-in-command-line-user-mode\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\\\/\\\/kb.n0c.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Articles\",\"item\":\"https:\\\/\\\/kb.n0c.com\\\/en\\\/knowledge-base\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"How to Import\\\/Export Database in Command Line (User Mode)\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/kb.n0c.com\\\/#website\",\"url\":\"https:\\\/\\\/kb.n0c.com\\\/\",\"name\":\"N0C KB\",\"description\":\"Official documentation of the N0C hosting platform\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/kb.n0c.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Import\/Export Database in Command Line (User Mode) - N0C KB","description":"This article explains how to import\/export database in command line (user mode).","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/","og_locale":"en_US","og_type":"article","og_title":"How to Import\/Export Database in Command Line (User Mode) - N0C KB","og_description":"This article explains how to import\/export database in command line (user mode).","og_url":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/","og_site_name":"N0C KB","article_modified_time":"2026-08-31T16:11:04+00:00","og_image":[{"width":1000,"height":426,"url":"https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/","url":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/","name":"How to Import\/Export Database in Command Line (User Mode) - N0C KB","isPartOf":{"@id":"https:\/\/kb.n0c.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/#primaryimage"},"image":{"@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/#primaryimage"},"thumbnailUrl":"https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1.jpg","datePublished":"2022-04-21T17:35:28+00:00","dateModified":"2026-08-31T16:11:04+00:00","description":"This article explains how to import\/export database in command line (user mode).","breadcrumb":{"@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/#primaryimage","url":"https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1.jpg","contentUrl":"https:\/\/kb.n0c.com\/wp-content\/uploads\/2024\/01\/Importation_Exportation_EN-1.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/kb.n0c.com\/en\/knowledge-base\/database-import-export-in-command-line-user-mode\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/kb.n0c.com\/"},{"@type":"ListItem","position":2,"name":"Articles","item":"https:\/\/kb.n0c.com\/en\/knowledge-base\/"},{"@type":"ListItem","position":3,"name":"How to Import\/Export Database in Command Line (User Mode)"}]},{"@type":"WebSite","@id":"https:\/\/kb.n0c.com\/#website","url":"https:\/\/kb.n0c.com\/","name":"N0C KB","description":"Official documentation of the N0C hosting platform","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/kb.n0c.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb\/9434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb"}],"about":[{"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/types\/ht_kb"}],"author":[{"embeddable":true,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/comments?post=9434"}],"version-history":[{"count":24,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb\/9434\/revisions"}],"predecessor-version":[{"id":23988,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb\/9434\/revisions\/23988"}],"wp:attachment":[{"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/media?parent=9434"}],"wp:term":[{"taxonomy":"ht_kb_category","embeddable":true,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb-category?post=9434"},{"taxonomy":"ht_kb_tag","embeddable":true,"href":"https:\/\/kb.n0c.com\/en\/wp-json\/wp\/v2\/ht-kb-tag?post=9434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}