Importing MySQL Gzipped Dump File via Terminal
When dealing with MySQL databases, it's common to export and import data for various reasons, such as backups or transferring data between environments. In this concise guide, we'll focus on importing a gzipped MySQL dump file using the terminal on a system running Ubuntu.
Step 1: Navigate to the Directory
Ensure that you're in the directory where your gzipped MySQL dump file is located. You can use the cd
command to navigate to the appropriate directory.
cd /path/to/your/directory
Step 2: Use Gunzip and MySQL Commands
Execute the following command, replacing placeholders with your actual values:
gunzip < your_dump_file.sql.gz | mysql -u your_username -p your_database_name
your_dump_file.sql.gz
: Replace this with the name of your gzipped dump file.your_username
: Your MySQL username.your_database_name
: The name of your MySQL database.
After entering the command, you'll be prompted to enter the MySQL password associated with the specified username. Type the password and press Enter.
Example:
gunzip < my_database_dump.sql.gz | mysql -u john_doe -p my_database
This command unzips the dump file (my_database_dump.sql.gz
) and pipes it directly to the mysql
command, which then imports the data into the specified MySQL database (my_database
) using the provided username (john_doe
).
Add Verbose to show more info
gunzip -v < your_dump_file.sql.gz | mysql -v -u your_username -p your_database_name
Conclusion:
By following these simple steps, you can efficiently import a gzipped MySQL dump file via the terminal on your Ubuntu system. This process is valuable for tasks like restoring backups or migrating data between different environments. Remember to replace the placeholders with your actual information for a smooth import process.