Pankaj Sanam


Import Export SQL file using the command line

Import Export SQL file using the command line

Pankaj Sanam's photo
Pankaj Sanam
·Apr 19, 2020·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

I always forget this so I'm going to save it here. This way I can import the SQL files directly in the terminal.

The following command will import the database:

mysql -u username -p database_name < /file_path/file_name.sql

The above command does not import the triggers and procedures by default.

Use -R and --triggers flags to import the routines and triggers.

Export MySQL database with the below command:

mysqldump -u username -p database_name > /file_path/file_name.sql

Thank you for reading!

Share this


🙋‍♂️ Hello there,

My name is Pankaj, and I am the author of Slashism. I hope that you learn something useful today.

If you like my content and want to stay updated then subscribe to my newsletter in the header.

You can also follow me on Twitter and say hello.

If you would like to request a particular article/topic covered or would want to discuss something, then please start a discussion here on Github Discussions

⭐ Keep learning, keep growing ⭐