{"id":5439,"date":"2015-01-09T23:40:02","date_gmt":"2015-01-09T15:40:02","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=5439"},"modified":"2023-04-28T09:47:21","modified_gmt":"2023-04-28T09:47:21","slug":"import-and-export-mysql-database-command-line-in-linux","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/import-and-export-mysql-database-command-line-in-linux\/","title":{"rendered":"How to Import and Export MySQL Database Command line in Linux"},"content":{"rendered":"<p>MySQL is a widely-used open-source relational database management system. Importing and exporting MySQL databases are common tasks when managing or migrating data between servers or applications.<\/p>\n<p>In this guide, we will demonstrate how to import and export MySQL databases using the command line in Linux.<\/p>\n<h2>Step 1: Export MySQL Database<\/h2>\n<p>To export a MySQL database, use the mysqldump utility. Replace username, password, and database_name with the appropriate values for your MySQL server and database:<\/p>\n<pre>\r\nmysqldump -u username -p password database_name > database_name.sql\r\n<\/pre>\n<p>The command above will create a new file called database_name.sql containing the SQL statements needed to recreate the database.<\/p>\n<p>If you want to export a specific table from the database, you can add the table name after the database name:<\/p>\n<pre>\r\nmysqldump -u username -p password database_name table_name > table_name.sql\r\n<\/pre>\n<h2>Step 2: Import MySQL Database<\/h2>\n<p>To import a MySQL database, use the mysql command. Replace username, password, database_name, and file.sql with the appropriate values for your MySQL server, database, and SQL file:<\/p>\n<pre>\r\nmysql -u username -p password database_name < file.sql\r\n<\/pre>\n<p>The command above will import the SQL statements from file.sql into the specified database.<\/p>\n<p>If you need to import a specific table into an existing database, make sure the SQL file contains only the statements related to that table, and then execute the command above.<\/p>\n<h2>Programs Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">MySQL<\/span> - An open-source relational database management system used for managing databases and organizing data.<\/li>\n<li><span class=\"fw-bold\">mysqldump<\/span> - A utility for exporting the structure and data of a MySQL database or table to an SQL file.<\/li>\n<li><span class=\"fw-bold\">mysql<\/span> - A command-line tool for interacting with a MySQL server, which can be used for tasks such as importing SQL files into a database.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>By following this guide, you have learned how to import and export MySQL databases using the command line in Linux. These tasks are essential for managing and migrating data between servers or applications. With a good understanding of these commands, you can efficiently handle your MySQL databases in various situations.<\/p>\n<p>If you have any questions, comments, or suggestions for improvements, please feel free to share your thoughts. Your feedback helps us provide the most accurate and useful information possible.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MySQL is a widely-used open-source relational database management system. Importing and exporting MySQL databases are common tasks when managing or migrating data between servers or applications. In this guide, we&#8230;<\/p>\n","protected":false},"author":6,"featured_media":5283,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[2055,1008],"tags":[1260,1585],"class_list":["post-5439","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-centos","category-mysql","tag-centos-7-1","tag-mysql"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5439","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=5439"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/5439\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/5283"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=5439"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=5439"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=5439"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}