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!
Connect to your server use pem file.
ssh -i ./name_file.pem [email protected]
The xxx.xxx.xxx.xxx what is your IP address.
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.
Zip file sql for downloading.
gzip -f sql_export_file_name.sql
Download to localhost.
Open your terminal in PC to connect and download.
scp -i "name_file.pem" ec2-us[email protected]://home/ec2-user/sql_export_file_name.sql.gz .
Come back your server connect and remove that file if you want
rm -rf sql_export_file_name.sql.gz