{"id":9,"date":"2017-11-11T17:56:34","date_gmt":"2017-11-11T23:56:34","guid":{"rendered":"https:\/\/tech.my-netsol.com\/?p=9"},"modified":"2017-11-11T17:56:34","modified_gmt":"2017-11-11T23:56:34","slug":"creating-a-mysql-backup","status":"publish","type":"post","link":"https:\/\/tech.my-netsol.com\/?p=9","title":{"rendered":"Export MySQL Databases using Command line"},"content":{"rendered":"\n<p>MySQL provides us the utility called <code>mysqldump<\/code> to export our databases. It is very easy to use utility. You can export a single database or multiple databases using this command or utility. So, Let\u2019s see how to export a single database using mysqldump.<\/p>\n\n\n\n<p>To export a single database using mysqldump, execute the following command on your server. To execute this command, you first have to connect to your server via SSH.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ mysqldump -uUSERNAME -p DB_NAME &gt; exported.sql<\/pre>\n\n\n\n<p>Do not forget to replace Username and database name in the command. It will ask you for the password of the user you are using as a username. Enter the correct password and it will start exporting database in the file you have mentioned in the command. In our case, it is <code>exported.sql<\/code>.<\/p>\n\n\n\n<p>It means that the whole database will be exported to the file named <code>exported.sql<\/code>. You can export to any file you want. Just replace the file name and you are good to go.<\/p>\n\n\n\n<p>Now, Let\u2019s see how to export MySQL database except a few tables. This is not a widely used feature because you will mostly export the database with all the tables in it. Execute the following command to export the database except for a few tables.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ mysqldump -uUSERNAME -p DB_NAME --ignore-table=DB_NAME.TABLE_NAME &gt; exported.sql<\/pre>\n\n\n\n<p>Again, do not forget to replace variables with the actual username, database name, and table name. If you want to ignore multiple tables in the export process, just add an extra <code>--ignore-table<\/code> options in your commands with the tables you want to ignore.<\/p>\n\n\n\n<p>So, this is how you can export MySQL databases using the command line. Now, Let\u2019s see how to import MySQL databases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Import MySQL database using Command line<\/h2>\n\n\n\n<p>Importing MySQL database is even easier. We can use the main <code>mysql<\/code> command to import the databases that are exported and stored as an SQL file. But you first have to create MySQL database in which you want to import your SQL file.<\/p>\n\n\n\n<p>So, Let\u2019s first create a MySQL database. Login to your MySQL server using the command given below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ mysql -uUSERNAME -p;<\/pre>\n\n\n\n<p>After logging in, Execute the following command to create a database in your MySQL server.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; CREATE DATABASE DB_NAME;<\/pre>\n\n\n\n<p>Now, Let\u2019s import the SQL file in our brand new database. Execute the following command to import MySQL database from an SQL file.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">$ mysql -uUSERNAME -p DB_NAME &lt; import_file.sql<\/pre>\n\n\n\n<p>It will ask you for the password. Enter the password and it will start importing data from the SQL file you have mentioned in the command. So, this is how you can import databases in MySQL.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL provides us the utility called mysqldump to export our databases. It is very easy to use utility. You can export a single database or multiple databases using this command or utility. So, Let\u2019s see how to export a single database using mysqldump. To export a single database using mysqldump, execute the following command on &#8230; <a title=\"Export MySQL Databases using Command line\" class=\"read-more\" href=\"https:\/\/tech.my-netsol.com\/?p=9\" aria-label=\"Read more about Export MySQL Databases using Command line\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-9","post","type-post","status-publish","format-standard","hentry","category-linux"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=\/wp\/v2\/posts\/9","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9"}],"version-history":[{"count":0,"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=\/wp\/v2\/posts\/9\/revisions"}],"wp:attachment":[{"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.my-netsol.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}