How to Import a Database via Command Line (SSH)

Advanced users may wish to use SSH to access and make changes to their account, offering a more robust set of options with fewer limitations. These instructions will require a basic familiarity with SSH. If you are interested in learning to use SSH, please check the article below for information on how to get started:

To import your database after you have logged in to your account with SSH:

Note: Your database file must be in .sql format, it cannot be compressed in a .zip or .tar.gz.
  1. Upload your database to your home directory (This may be done with cPanel File Manager, an FTP client, or SSH).
  2. If the database does not exist, please create a database, a user, and give the user full privileges to the database. Note the username and password.

    For assistance with creating a Database and Database user, please see the article below:

  3. Log into your server via SSH.
  4. Use the ls -l command to verify that the file is in your current directory.
  5. If the file is not present, upload/move the file to the correct directory, or navigate to the directory where the file is located.
  6. Enter the following command, replacing ‘user_name’, ‘database_name, and ‘file.sql’ with the correct values for your database and file:
    mysql -p -u user_name database_name < file.sql
  7. You will be prompted for your database user password, and then your database will be imported.

 

Notes:

  • HostGator recommends using the database user with the database user’s password.
  • Make sure your database name and username has your HostGator username prefix (e.g. ‘username_databasename’; ‘username_databaseusername’).