Importing a database via SSH using cPanel

Started 9 months ago by Gurkha.Host in Gurkha.Host, cPanel

This documentation will help you import large database files into your database using SSH.

Body

How to Import a Database Over SSH on cPanel?

phpMyAdmin allows you to import databases up to 50 MB; sometimes a little less, when the database has a large number of rows. If importing with phpMyAdmin failed, you can import your database using SSH by following these steps:

ย 

Step 1 - Preparation

  • Upload the database file in .sql format to your website's public_html folder. You can do so via FTP

  • Create a new database or clear the one you plan to import into

ย 

Step 2 - Connecting via SSH

  • Connect to your hosting via SSH

  • Use the ls command to ensure you are in the root directory, that is, public_html. If you are located in a different directory, use the ls and cd commands to reach it. For example, the process will be similar to this, replacing domain.tld with your domain name:

cd domains
cd domain.tld
cd public_html
  • If the database backup is displayed, go to the next step.

  • If you the backup file is missing, use the File Manager to verify the file is correctly stored in the public_html folder

ย 

Step 3 - Import the Database

To import the database, use this command:

ย 

mysql -u database_username -p database_name < file.sql

ย 

If the parameters of your database are:

  • MySQL Database name: user_database

  • MySQL Username: user_admin

  • Uploaded database file: database.sql

ย 

The command will look like this:

ย 
mysql -u user_admin -p user_database < database.sql

ย 

After that you will need to enter the database password - the importing process will start immediately. The import will take some time depending on the size of your database.

ย 

When it is completed, a new line will appear:

ย 

-bash-4.2$

ย 

This line means that the importing process is done, you will see your database tables in phpMyAdmin.

ย 

That's it!

ย 

Important: You can also use sql file splitter tools to split your large sql files and import to your database.ย 

  • No one is replied to this thread yet. Be first to reply!