HOW CAN I IMPORT A MYSQL DATABASE FROM THE TERMINAL?


In some cases, you do not have a PhpMyAdmin, and even if you do, it will always be faster to use the command line to import large databases.
As a general rule, I export all databases in compressed format (gzip). This makes them take up less space and I can upload or download them to other servers faster.
So, to have a single terminal command that does all the work:

gunzip < [dir/subdir/backup_DB.sql.gz]  | mysql -h [host_ip_or_name] -u [user_name] -p [database_name]


You only have to change what is between "[ ]" for your real data.
An example would look like this:

gunzip < [dir/subdir/backup_DB.sql.gz]  | mysql -h [host_ip_or_name] -u [user_name] -p [database_name]
Tags

Have Any Project in Mind?

If you want to do something in Drupal maybe you can hire me.

Either for consulting, development or maintenance of Drupal websites.