How to export database and download to localhost from EC2
You have the pem file and want to connect to server, export database then need to download it to your machine in localhost.
Ok. Let’s go!
Step 1
Connect to your server use pem file.
ssh -i ./name_file.pem [email protected]
The xxx.xxx.xxx.xxx what is your IP address.
Step 2
Dump databse to sql file.
mysqldump -udb_user -p db_name > sql_export_file_name.sql
db_user: is your database user name db_name: is your database name in mysql sql_export_file_name: free with your set
Command will ask you about your databse user password. Please enter and wait for momment to export.
Step 3
Zip file sql for downloading.
gzip -f sql_export_file_name.sql
Step 4
Download to localhost.
Open your terminal in PC to connect and download.
scp -i "name_file.pem" [email protected]://home/ec2-user/sql_export_file_name.sql.gz .
It’s done.
Come back your server connect and remove that file if you want
rm -rf sql_export_file_name.sql.gz