Knowledge Base

How Import Databases Using Command Line SSH

Using SSH can be a superior way to manage the files and databases on your account. Using a simple command, you can import a MySQL database into an existing database on your account. SSH access is required for this process. Please see our article on getting SSH access if it has not yet been enabled on your account.

Essential Preparations for Database Import via SSH

Before diving into the technical process of importing databases via SSH, ensuring you have everything ready is crucial. This preparation will streamline your workflow and prevent common pitfalls. Here's a checklist to get you started:

  1. SSH Access - Confirm you have SSH access to both the source and target servers.
  2. Database Credentials - Gather the necessary credentials for accessing your databases.
  3. Command Line Knowledge - Basic familiarity with command line operations is essential.
  4. Database Backup - Always back up your databases before attempting any import to avoid data loss.
  5. Required Software - Ensure you have the necessary database management tools installed, like MySQL or PostgreSQL clients.

Using Command Line (SSH) to import your MySQL database

The file must be in .sql format. It can not be compressed in a .zip or .tar.gz file.

  1. Upload the SQL file to the server via the file manager or an FTP client.
  2. If the database does not exist, please create a database and a user. Ensure to give the user full privileges to the database. Please take note of the username and password.
  3. Log in to the server through SSH.
  4. Navigate to the directory where your .sql file is.
  5. Type this SSH command line:
    mysql -p -u user_name database_name < file.sql (replace 'user_name', 'database_name', and 'file.sql' with the actual name.)
  6. You will be prompted for your database user password, and then your database will be imported.

Bluehost recommends using the database user with the database user's password and not the cPanel main user and password. The -p flag will cause MySQL to prompt for your account's password. Do not put passwords in the command line in plain text, but let the system prompt for a password. This is for your own security. Make sure your database name and username has your Bluehost username prefix (e.g. 'username_databasename'; 'username_databaseusername').


To import a MySQL database via SSH, ensure you have SSH access and know your database credentials. Backup your database first. Upload the .sql file to the server. Then, SSH into the server, go to the file's location, and run mysql -p -u user_name database_name < file.sql, substituting with your information. Enter the database password when prompted. Make sure to use the proper names, including your Bluehost prefix for security.

If you need further assistance, feel free to contact us via Chat or Phone:

  • Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
  • Phone Support -
    • US: 888-401-4678
    • International: +1 801-765-9400

You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.

Did you find this article helpful?

* Your feedback is too short