{"id":710,"date":"2024-06-18T18:40:12","date_gmt":"2024-06-18T18:40:12","guid":{"rendered":"https:\/\/zalvis.com\/docs\/?p=710"},"modified":"2024-06-19T03:43:11","modified_gmt":"2024-06-19T03:43:11","slug":"easy-ways-to-export-and-import-mysql-databases","status":"publish","type":"post","link":"https:\/\/zalvis.com\/docs\/easy-ways-to-export-and-import-mysql-databases.html","title":{"rendered":"Easy Ways to Export and Import MySQL Databases"},"content":{"rendered":"<p>One of the most important components, when you make a website, is a database. Whether you use common CMS platforms like WordPress, Magento, Joomla, or other PHP frameworks such as Laravel, CakePHP, or CodeIgniter, you will probably need to integrate a database that stores the website data.<\/p>\n<p>In this article, we will focus on exporting and importing one of the most popular database management systems, MySQL. This knowledge will come in handy if you wish to transfer your database to another server or simply to create a database backup.<\/p>\n<p>There are two easy ways on how export and import MySQL databases:<\/p>\n<ul>\n<li>Use phpMyAdmin<\/li>\n<li>Use SSH command line<\/li>\n<\/ul>\n<p>Now we will explain each method in detail below, so read on!<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_81 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/zalvis.com\/docs\/easy-ways-to-export-and-import-mysql-databases.html\/#How_to_Export_and_Import_MySQL_Through_phpMyAdmin\" >How to Export and Import MySQL Through phpMyAdmin<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/zalvis.com\/docs\/easy-ways-to-export-and-import-mysql-databases.html\/#Exporting\" >Exporting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/zalvis.com\/docs\/easy-ways-to-export-and-import-mysql-databases.html\/#Importing\" >Importing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/zalvis.com\/docs\/easy-ways-to-export-and-import-mysql-databases.html\/#How_to_Export_and_Import_MySQL_Through_SSH_command_line\" >How to Export and Import MySQL Through SSH command line<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/zalvis.com\/docs\/easy-ways-to-export-and-import-mysql-databases.html\/#Exporting-2\" >Exporting<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/zalvis.com\/docs\/easy-ways-to-export-and-import-mysql-databases.html\/#Importing-2\" >Importing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/zalvis.com\/docs\/easy-ways-to-export-and-import-mysql-databases.html\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Export_and_Import_MySQL_Through_phpMyAdmin\"><\/span>How to Export and Import MySQL Through phpMyAdmin<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><span class=\"ez-toc-section\" id=\"Exporting\"><\/span><strong>Exporting<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>To export an existing MySQL database using phpMyAdmin, make sure you are logged in to your cPanel area first. Once you\u2019re in, type phpMyAdmin on the top right search bar and click on the option shown:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-711\" src=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8269.png\" alt=\"\" width=\"1019\" height=\"224\" srcset=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8269.png 1019w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8269-300x66.png 300w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8269-768x169.png 768w\" sizes=\"auto, (max-width: 1019px) 100vw, 1019px\" \/>A new browser window will open and the next step is to select the database you would like to export. Make sure you select the correct one, if there are multiple databases. Once the database is selected, click \u201cExport\u201d and on the \u201cExport Method\u201d option, choose Quick. Next, you can choose \u201cSQL\u201d format if you wish to re-import the database again elsewhere. Lastly, click Go.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-712\" src=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8270.jpeg\" alt=\"\" width=\"842\" height=\"449\" srcset=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8270.jpeg 842w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8270-300x160.jpeg 300w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8270-768x410.jpeg 768w\" sizes=\"auto, (max-width: 842px) 100vw, 842px\" \/><\/p>\n<p>Now all you have to do is to wait for a few minutes (or seconds, if your database is quite small), until the export process is complete. You should now be able to find the .sql file within your Downloads folder.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Importing\"><\/span><strong>Importing<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Again, you will need to go to your cPanel and navigate to phpMyAdmin<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-711\" src=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8269.png\" alt=\"\" width=\"1019\" height=\"224\" srcset=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8269.png 1019w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8269-300x66.png 300w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8269-768x169.png 768w\" sizes=\"auto, (max-width: 1019px) 100vw, 1019px\" \/>Prepare your SQL database file that you\u2019d like to import<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-713\" src=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8271.jpeg\" alt=\"\" width=\"719\" height=\"479\" srcset=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8271.jpeg 719w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8271-300x200.jpeg 300w\" sizes=\"auto, (max-width: 719px) 100vw, 719px\" \/>Now that you have the SQL file ready, go back to phpMyAdmin, and select the empty database (If you haven\u2019t created it yet, go back to cPanel &gt; MySQL Database Wizard). After selecting the database, go ahead and click the \u201cImport\u201d button on the top bar. Next, click \u201cChoose File\u201d to select the .sql file. Then scroll down and click Go.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-714\" src=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8272.jpeg\" alt=\"\" width=\"843\" height=\"450\" srcset=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8272.jpeg 843w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8272-300x160.jpeg 300w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8272-768x410.jpeg 768w\" sizes=\"auto, (max-width: 843px) 100vw, 843px\" \/><\/p>\n<p>Importing a MySQL database will take a few minutes normally. When it is done, there will be a prompt saying \u201cImport has been successfully finished\u201d and you will be able to see the content of your SQL database within the previously empty one.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"How_to_Export_and_Import_MySQL_Through_SSH_command_line\"><\/span>How to Export and Import MySQL Through SSH command line<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Note: To export and import MySQL via the command line, the cPanel SSH access must be enabled. Make sure you do know basic SSH commands to login to your server via Terminal or PuTTY. You will also need to have the database credentials such as the database name, user, and password.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Exporting-2\"><\/span>Exporting<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>First, open your terminal or PuTTY and login to your hosting account. Once logged in, navigate to the directory where you wish the SQL database to be exported and type in this command below:<\/p>\n<p>mysqldump -u DBUSERNAME -p DBNAME &gt; dbbackup.sql<\/p>\n<p>Make sure to replace the DBUSERNAME with the correct database username and DBNAME with the correct database name.<\/p>\n<p>Here\u2019s the breakdown of the command:<\/p>\n<p>mysqldump is the initial command to export the MySql database.<\/p>\n<p>-u clarifies the username of MySQL database<\/p>\n<p>-p specifies the need to use the database password<\/p>\n<p>dbbackup.sql : the result of the export<\/p>\n<p>After typing the command above, you will then be asked to enter the database password. If the password is correct, the export progress will start. Once finished, type in the command ls and the dbbackup.sql should be visible.<\/p>\n<p>Here\u2019s a screenshot taken from Terminal for reference:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-715\" src=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8273.jpeg\" alt=\"\" width=\"836\" height=\"202\" srcset=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8273.jpeg 836w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8273-300x72.jpeg 300w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8273-768x186.jpeg 768w\" sizes=\"auto, (max-width: 836px) 100vw, 836px\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"Importing-2\"><\/span><strong>Importing<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Luckily, importing a MySQL database via SSH includes almost the same exact steps as exporting one. Once you are logged in to your server via Terminal or PuTTY, navigate to the directory where you store the SQL file that you wish to import to an existing empty database. Then run this command:<\/p>\n<p>mysql -u DBUSERNAME -p DBNAME &lt; dbbackup.sql<\/p>\n<p>Don\u2019t forget to replace the DBUSERNAME and DBNAME to the correct database username and name accordingly.<\/p>\n<p>Command Breakdown:<\/p>\n<p>mysql is the initial command to import the MySql database.<\/p>\n<p>-u clarifies the username of MySQL database<\/p>\n<p>-p specifies the need to use the database password<\/p>\n<p>dbbackup.sql : the SQL file that will be imported<\/p>\n<p>You will then be prompted to input the correct password and afterward the import progress will be initiated. Depending on the database size, it can take a few seconds or minutes for the database import to finish.<\/p>\n<p>Here\u2019s another screenshot that can help you:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-716\" src=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8274.jpeg\" alt=\"\" width=\"835\" height=\"202\" srcset=\"https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8274.jpeg 835w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8274-300x73.jpeg 300w, https:\/\/zalvis.com\/docs\/wp-content\/uploads\/2024\/06\/IMG_8274-768x186.jpeg 768w\" sizes=\"auto, (max-width: 835px) 100vw, 835px\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Now that you see how impeccably easy it is to import or export a MySQL database, there\u2019s no need to worry if there comes a day when you need to do either. For the beginners, it\u2019s always recommended to export or import the databases via phpMyAdmin as it\u2019s much easier and GUI based. For the more experienced users out there, feel free to type in those commands above from your terminal and voila! Your SQL database will be exported\/imported in no time!<\/p>\n<div class=\"eljkx69e0f44b25b7c\" >If you enjoyed this article, then you\u2019ll love Zalvis's Cloud Hosting platform. Turbocharge your website and get 24\/7 support from our veteran team. Our world-class hosting infrastructure focuses on auto-scaling, performance, and security. Let us show you the Zalvis difference! <a href=\"https:\/\/zalvis.com\/\">Check out our services.<\/a><\/div><style type=\"text\/css\">\r\n@media screen and (min-width: 1201px) {\r\n.eljkx69e0f44b25b7c {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 993px) and (max-width: 1200px) {\r\n.eljkx69e0f44b25b7c {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 769px) and (max-width: 992px) {\r\n.eljkx69e0f44b25b7c {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (min-width: 768px) and (max-width: 768px) {\r\n.eljkx69e0f44b25b7c {\r\ndisplay: block;\r\n}\r\n}\r\n@media screen and (max-width: 767px) {\r\n.eljkx69e0f44b25b7c {\r\ndisplay: block;\r\n}\r\n}\r\n<\/style>\r\n","protected":false},"excerpt":{"rendered":"<p>One of the most important components, when you make a website, is a database. Whether you use common CMS platforms like WordPress, Magento, Joomla, or other PHP frameworks such as Laravel, CakePHP, or CodeIgniter, you will probably need to integrate a database that stores the website data. In this article, we will focus on exporting [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9],"tags":[],"class_list":["post-710","post","type-post","status-publish","format-standard","hentry","category-cpanel-hosting"],"_links":{"self":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/710","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/comments?post=710"}],"version-history":[{"count":3,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/710\/revisions"}],"predecessor-version":[{"id":729,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/posts\/710\/revisions\/729"}],"wp:attachment":[{"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/media?parent=710"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/categories?post=710"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zalvis.com\/docs\/wp-json\/wp\/v2\/tags?post=710"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}