Syntax
$ mysql -u username -p database_name < path_to_mysql_file_here
Importing existing MYSQL database with filename "wordpress.sql" stored at directory "/home/nishant/", Username is "root", terminal will prompt for asking password.
$ mysql -u root -p wordpress < /home/nishant/wordpress.sql
Syntax
$ mysqldump -p -u username database_name > path_to_mysql_file_here
Exporting MYSQL database to filename "db.sql" stored at directory "/home/nishant/", Username is "root", terminal will prompt for asking password.
$ mysqldump -p -u root wordpress > /home/nishant/db.sql
Learn here => How To Create file with TimeStamp in Shell Script
Following shell script written for exporting mysql database to file along with timestamp.
#!/bin/sh # Database backup configuration DB_USER="root" DB_PASS="root" FILE_PATH=~/Desktop/ cd $FILE_PATH # WordPress Backup configuration DATABASE="wordpress" FILE="$DATABASE_$(date +%d%m%Y_%H%M%S).sql" ZIPFILE="$FILE.zip" mysqldump -p$DB_PASS -u $DB_USER $DATABASE > $FILE_PATH$FILE zip $FILE_PATH$ZIPFILE $FILE sleep 10 rm $FILE