Introduction
MySQL and MariaDB are popular relational database management systems used in web development. In this guide, we'll walk through the steps to import and export databases in MySQL or MariaDB using command-line tools.
Prerequisites
Before proceeding, ensure you have:
- A MySQL or MariaDB server installed
- The MySQL or MariaDB command-line client installed on your system
Exporting a Database
- Using mysqldump: Use the following command to export a database:
mysqldump -u username -p database_name > filename.sql
Replace username
with your MySQL or MariaDB username, database_name
with the name of the database you want to export, and filename.sql
with the desired name for the exported SQL file.
Importing a Database
- Using mysql: Use the following command to import a database:
mysql -u username -p database_name < filename.sql
Replace username
with your MySQL or MariaDB username, database_name
with the name of the database you want to import into, and filename.sql
with the path to the SQL file you want to import.
Conclusion
Congratulations! You have successfully learned how to import and export databases in MySQL or MariaDB using command-line tools. This process is useful for backing up and restoring databases, migrating data between servers, and more.