How To Import A Database Via SSH In cPanel

To import a database via SSH is often faster and more reliable than using phpMyAdmin, especially for large databases. With secure shell access, you can directly upload and restore .sql backup files using command-line tools like MySQL and gzip. With Web Hosting from Domains.co.za, you can easily access your server using SSH on cPanel to manage and import a database efficiently and securely.

How to Import a Database via SSH in cPanel

This method is ideal for large databases that timeout or fail in phpMyAdmin. Here are the steps to import a database using SSH on cPanel.

1. Login to your Domains.co.za account.

How To Import A Database via SSH in cPanel - Domains.co.za Login

2. Click on Manage Services on the left-hand side and select Web Hosting from the drop-down menu.

How To Import A Database via SSH in cPanel - Manage Web Hosting

3. Click Manage next to your website’s domain name.

How To Import A Database via SSH in cPanel - cPanel Security Section

4. Next, click the Login button next to Control Panel to access your cPanel dashboard.

5. Scroll down to Security and click SSH Access.

How To Import A Database via SSH in cPanel - SSH Access

6. Generate or manage your SSH key if you haven’t done so already.

7. Use an SSH client (like Terminal for macOS/Linux or PuTTY for Windows) to connect to your server.

8. Run the following command to import your database:

mysql -u your_db_username -p your_db_name < /path/to/your-database.sql

9. Replace your_db_username, your_db_name, and the file path accordingly.

10. If your file is zipped as .sql.gz, use this command instead:

gunzip < your-database.sql.gz | mysql -u your_db_username -p your_db_name

11. Enter your MySQL password when prompted.

12. Wait for the process to complete; you will be returned to the command line when it’s done.

Note: SSH access must be enabled on your hosting account before you can use the commands mentioned above. Ensure that your .sql file is uploaded to your hosting account via FTP (File Transfer Protocol) client or cPanel’s File Manager before running the import command.

You can check your MySQL database name and user in cPanel > MySQL® Databases.

Additional Information

What is SSH in Web Hosting?

SSH (Secure Shell) is a cryptographic network protocol that allows for secure remote access to your web server. It encrypts the connection between your computer and the remote server, protecting sensitive database credentials and data from being intercepted.

When it comes to importing databases, SSH provides a secure and often faster alternative to web-based tools like phpMyAdmin, especially for large databases without worrying about upload size limits or timeout issues for very large SQL files.

Tips for Importing a Database via SSH in cPanel

SSH gives you direct command-line access to the server, allowing for more control over the import process and troubleshooting.

  • Use correct file paths – relative to your home directory or absolute.
  • Make sure you have the correct database username, password, and database name.
  • Gzipped .sql.gz files save space and reduce upload time.
  • Ensure the database already exists, and your user has the correct privileges.
  • Use exit to disconnect from the SSH session safely when you’re done.
  • Back up your existing database before importing, in case of accidental data loss or overwrites.
  • Avoid running other resource-heavy tasks while importing large databases.
  • Always thoroughly test your website after importing to ensure functionality.

What Our Customers say...