How to import a large MySQL database via SSH Print

  • 0

phpMyAdmin is fine for smaller databases, but large imports can time out. Importing over SSH is faster and more reliable.

  1. Create the database and user in cPanel (see How to create a MySQL database).
  2. Upload your .sql file to your home directory using File Manager or SFTP. Compressed files (.sql.gz) save time.
  3. Connect via SSH (see How to connect via SSH).
  4. Run:
mysql -u cpuser_dbuser -p cpuser_dbname < backup.sql

For a compressed file:

gunzip < backup.sql.gz | mysql -u cpuser_dbuser -p cpuser_dbname
  1. Enter the database user's password when asked. The terminal shows nothing until the import finishes.

If it fails

  • If the dump contains CREATE DATABASE or USE lines near the top naming a different database, remove or comment them out.
  • "Access denied" means the user isn't assigned to the database or the password is wrong.
  • Delete the .sql file once done.

Was this answer helpful?

« Back