How to Import and Export MySQL Database Command line in Linux

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 will demonstrate how to import and export MySQL databases using the command line in Linux.

Step 1: Export MySQL Database

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:

mysqldump -u username -p password database_name > database_name.sql

The command above will create a new file called database_name.sql containing the SQL statements needed to recreate the database.

See also  How to Install osCommerce on CentOS 7.1

If you want to export a specific table from the database, you can add the table name after the database name:

mysqldump -u username -p password database_name table_name > table_name.sql

Step 2: Import MySQL Database

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:

mysql -u username -p password database_name < file.sql

The command above will import the SQL statements from file.sql into the specified database.

See also  How to Start, Stop, Restart PostgreSQL Database Server on Linux CentOS 6.2 Server

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.

Programs Mentioned:

  • MySQL - An open-source relational database management system used for managing databases and organizing data.
  • mysqldump - A utility for exporting the structure and data of a MySQL database or table to an SQL file.
  • mysql - A command-line tool for interacting with a MySQL server, which can be used for tasks such as importing SQL files into a database.
See also  How to Setup a Dedicated Server for your Website in Just 9 Steps

Conclusion

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.

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.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *