HoganHost blog

How to Upload and Import an SQL Database in cPanel and via Terminal (SSH)

How to Upload and Import an SQL Database in cPanel and via Terminal (SSH)

Importing an SQL database is essential for website migration, backups, or setting up a new project. This guide covers two simple methods: using cPanel (phpMyAdmin) for beginners and SSH (Terminal) for advanced users.

With cPanel, you can easily upload and import an SQL file via phpMyAdmin, making it a user-friendly option. For larger databases, SSH (Terminal) offers a faster and more efficient way to import using MySQL commands.

Follow our step-by-step instructions to restore your database seamlessly and keep your website running smoothly.

Method 1: Import an SQL Database Using cPanel (phpMyAdmin)

Step 1: Log in to cPanel

  1. Open your web browser and go to: https://yourdomain.com/cpanel.
  2. Enter your cPanel username and password.

Step 2: Open phpMyAdmin

  1. In cPanel, scroll down to the Databases section.
  2. Click on phpMyAdmin.

Step 3: Select the Database

  1. In phpMyAdmin, look at the left sidebar.
  2. Click on the database where you want to import the SQL file.

Step 4: Upload and Import the SQL File

  1. Click the Import tab at the top.
  2. Under “File to Import,” click Choose File and select your .sql file.
  3. Leave all settings as default and click Go.
  4. Wait for the process to complete. If successful, you’ll see a green success message.

Done! Your database is now imported using cPanel!


Method 2: Import an SQL Database Using SSH (Terminal)

If your SQL file is large or you prefer the command line, use SSH to import your database efficiently.

Step 1: Upload the SQL File

Before importing, you need to upload your .sql file to the server.

Option 1: Upload via cPanel File Manager

  1. Go to cPanel > File Manager.
  2. Navigate to /home/your_cpanel_username/ (Recommended: Do NOT upload inside public_html for security reasons).
  3. Click Upload, select your .sql file, and wait for it to finish.

Option 2: Upload via FTP (FileZilla)

  1. Open FileZilla and connect using your FTP credentials.
  2. Upload your SQL file to a safe location (e.g., /home/your_cpanel_username/).

Step 2: Access SSH (Terminal)

If you have SSH access, follow these steps:

  1. Open your terminal (Mac/Linux) or use PuTTY (Windows).
  2. Connect to your server:
    ssh your_cpanel_username@your_server_ip -p 22
    • Replace your_cpanel_username with your actual cPanel username.
    • Replace your_server_ip with your server’s IP address.

Step 3: Import the SQL File Using MySQL Command

Once connected via SSH, use the following command:

mysql -u your_mysql_username -p your_database_name < /home/your_cpanel_username/yourfile.sql
  • Replace your_mysql_username with your MySQL user (you can check this in cPanel > MySQL Databases).
  • Replace your_database_name with your actual database name.
  • Replace yourfile.sql with your SQL file name and correct path.

Enter your MySQL password when prompted. If successful, the import will complete without any message.

Step 4: Verify the Import

To check if your tables were imported correctly, run this command:

mysql -u your_mysql_username -p -e "SHOW TABLES FROM your_database_name;"

If you see a list of tables, your import was successful! 🎉

Step 5: Delete the SQL File for Security

Once the database is imported, remove the SQL file to prevent unauthorized access:

rm /home/your_cpanel_username/yourfile.sql

Done! You have successfully imported your database using SSH!


Troubleshooting Common Issues

Access Denied Error

  • Ensure you are using the correct MySQL username and password.
  • Check your MySQL user’s privileges in cPanel > MySQL Databases.

No Database Selected Error

  • Make sure the database exists before importing.
  • You can create a new database in cPanel > MySQL Databases.

Large SQL File Not Importing in phpMyAdmin

  • Use SSH instead (Method 2) to bypass phpMyAdmin limits.
  • If using cPanel, increase the upload limit in MultiPHP INI Editor.

Conclusion

Now you know how to import an SQL database using both cPanel (phpMyAdmin) and SSH (Terminal). If you’re a HoganHost customer, you can easily follow these steps to restore your database without technical support.

If you need web hosting with full database management, check out HoganHost for reliable hosting solutions!

Leave a Comment

Your email address will not be published. Required fields are marked *