How to restore a MySQL database from an sql dump?

Nov 23

In most common cases:

mysql -h localhost -u [user] -p [database_name] < [name_of_dump.sql]

In many other sources, it’s mentioned that you need to put the password without a space attached to the -p parameter. No need to do that – you will be prompted for password after you hit Enter.

And, yet, if you type your password attached to the -p parameter, the command will be saved in your history. And potentially, if someone gets that, you are in trouble.

If your mysql user doesn’t have password, omit the -p parameter.

mysql -h localhost -u [user] [database_name] < [name_of_dump.sql]