Importing a large database through phpMyAdmin can fail mid-way due to connection timeouts or file size limits, leaving your database in an incomplete state. Running the import over SSH sends the file directly to MySQL from the server, bypassing those restrictions entirely.
This guide covers uploading your SQL dump file to your server and running the MySQL import command from an SSH session. The same approach works for databases of any size.
Some database export tools include CREATE DATABASE or USE statements at the top of the dump file. These instruct MySQL to create or switch to a named database, which can conflict with the target database you have already set up in cPanel. Removing or commenting out these lines prevents the import from failing or writing data to the wrong database.
.sql file locally before uploading, or view it on the server using nano yourdumpfile.sql, replacing yourdumpfile.sql with your actual filename.CREATE DATABASE or USE. If you find them, comment them out by placing two hyphens and a space at the start of each line, like this:-- CREATE DATABASE `yourdatabasename`;
-- USE `yourdatabasename`;
Ctrl+X, then Y, then Enter to save.Your dump file is now ready to import without conflicting with your cPanel database setup.
The mysql command accepts a dump file as input using shell redirection. This sends the SQL statements directly to your target database without any file size or timeout constraints.
ls and check your .sql file appears in the output.mysql -u your_db_username -p your_database_name < yourdumpfile.sql
Replace your_db_username with your cPanel database username, your_database_name with the name of the target database and yourdumpfile.sql with the filename of your dump file. If the file is in a different directory, provide the full path, for example /home/cpanelusername/backups/yourdumpfile.sql.
Enter, MySQL will ask for the password. Type it and press Enter again. The password will not appear on screen as you type – this is expected behaviour.
Your database has been imported. You can verify the contents by logging in to phpMyAdmin from cPanel and browsing the target database tables.
An immediate error usually means MySQL could not authenticate or could not find the target database. Check that the database name and username are spelled exactly as they appear in cPanel, including any account prefix. Database names and usernames in cPanel are case-sensitive.
Errors mid-import are most often caused by conflicting CREATE DATABASE or USE statements in the dump file, or by the dump file being generated from a different MySQL version with incompatible syntax.
CREATE DATABASE or USE statements and comment them out as described in the first section of this guide.If MySQL returns a No such file or directory error, the path to your dump file is incorrect. Run ls in your current directory to confirm the file is present, or use find ~ -name "yourdumpfile.sql" to locate it. Provide the full path in the import command if the file is not in your current working directory.
You imported a MySQL database over SSH using the mysql command and shell redirection. This method handles databases of any size without the file upload limits or connection timeouts that affect phpMyAdmin.
Now that your database is in place, you may need to update your application’s database connection settings to point to the new database name and user. If you are migrating a WordPress site, see our guide on migrating from cPanel for the full migration process. For connecting to MySQL from a remote application, see our guide on connecting to MySQL with an SSH tunnel.
Our cPanel hosting plans include full SSH access and MySQL database management as standard.
Launch your website with our reliable cPanel hosting with unlimited bandwidth and expert support.
Get cPanel Hosting