How to Import a Database Over SSH

November 5, 2024 / Security and Backup

Importing a database over SSH is faster and more reliable for large files. It bypasses size limits and provides secure, direct control over the process, making it ideal for handling large or sensitive databases.

If phpMyAdmin’s import limit (usually around 256 MB) isn’t sufficient for your database size, you can import it through SSH with these steps:

  1. Preparation
    1. Upload the Database File: Use FTP or a file manager to place the database file in your website’s “public_html” folder.
    2. Prepare the Database: Create a new database or clear an existing one for the import.
    3. Verify Database Password: If you’re unsure about your database password, reset it to ensure accuracy.
  2. Connect through SSH
    1. Log into Your Hosting Account through SSH.
    2. Navigate to the Root Directory (public_html).
    3. Confirm the database backup file is in “public_html.” If it is missing, check the upload location.
  3. Import the Database
    1. Unzip if required: If the file is compressed (e.g., .sql.gz), run:
      gzip -d database_name.gz.sql

      Replace database_name with your actual database name.

    2. Run the Import Command:
      mysql -u database_username -p database_name < file.sql

      For example:

      mysql -u u123456789_admin -p u123456789_database < database.sql

      You will be prompted for your database password. Enter it to start the import. Once complete, a new line will appear: “-bash-4.2$.”
      Note: Import time will vary based on database size.

  4. Update the Configuration File
    To ensure your website connects to the new database:

    1. Open your site’s configuration file.
    2. Update the database name, username, password, and host as needed. Specific steps vary by CMS, so refer to your CMS documentation if necessary.

This way, you can import a database over SSH. If you run into any difficulty, feel free to contact our support staff as soon as possible.

Learn more by reading How to Import a New File in cPanel File Manager

Spread the love