Using Shell Access To Import A Large MySQL Database
How to Import a Database Using SSH on Shared or VPS/Dedicated Hosting
Importing a database through SSH can save time and effort, especially when working with large SQL files. This guide will walk you through the correct steps based on your hosting plan, whether it’s shared or VPS/Dedicated.
Step 1: SSH into Your Server
Start by accessing your server using SSH. The exact process depends on your hosting provider and the credentials provided to you.
Step 2: Navigate to the Directory with Your Backup File
Once logged in, navigate to the folder where your .sql
database backup file is located. For example, if the file is named new_databse.sql
and resides in the cPanel home directory for the user userna5
, use the following command:
Step 3: Confirm the Backup File Location
Verify the file exists in the directory by listing all files with the command:
You should see an output similar to this:
Ensure that the .sql
file is listed before proceeding.
Step 4: Import the Database
To import the database, you’ll need three pieces of information:
- user_name: Your cPanel username or the database user you’ve created and added to the database.
- data_base: The name of the database you’re importing into. For example,
userna5_tester
. - new_databse.sql: The name of your backup file.
Use the following syntax to run the command:
Here’s an example using the username userna5
and the database userna5_tester
:
Step 5: Enter the Password
After running the command, you’ll be prompted to enter the password for the specified user. For the cPanel username, use your cPanel password. If you’re using a database-specific user, provide the password you assigned to that user.
Example prompt:
Enter the password and press Enter
.
Step 6: Verify the Import
When the import process completes, you’ll return to the command prompt. You can verify the success of the import by checking your database in cPanel. Navigate to the Databases section, where you should see your database listed with a size (in megabytes) in the "Size" column.
Following these steps ensures a smooth and secure database import process. If you encounter any issues, double-check your file paths, database user credentials, and syntax. With practice, importing databases through SSH will become a simple and efficient part of your workflow.