Import database with MariaDB and command line

Databases are easy to import through phpMyAdmin, but this interface has limitations. It doesn’t deal well with large files, since a timeout cancels whatever is ongoing.

For larger files, it’s better to go through command line. Here are the steps to get it done:

  • First, make sure you have an empty database to begin with. myPhpAdmin is great to create it or to drop the tables of a placeholder database. The database should exist and have a name, but no tables.
  • On your terminal, enter into your server (or virtual server) with ssh, for example vagrant ssh.
  • Then, call up mysql and check that the target database exists.
  • exit mysql with ctrl + d and type the following command to import a previous sql backup or export: mysql -u external -p targetdatabasename < /shared/sourcedatabase.sql