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:

bash
/home/userna5

Step 3: Confirm the Backup File Location

Verify the file exists in the directory by listing all files with the command:

bash
ll

You should see an output similar to this:

plaintext
root@vps#### [/home/userna5]# ll
total 328
drwx--x--x 21 userna5 userna5 4096 Apr 30 15:40 ./
drwx--x--x 17 root root 4096 Dec 6 16:28 ../
-rw-r--r-- 1 root root 201467 Apr 30 15:40 new_databse.sql

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:

bash
mysql -p -u user_name data_base < new_databse.sql

Here’s an example using the username userna5 and the database userna5_tester:

bash
mysql -p -u userna5 userna5_tester < new_databse.sql

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:

plaintext
root@vps#### [/home/userna5]# mysql -p -u userna5 userna5_tester < new_databse.sql
Enter password:

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.

Share This Story, Choose Your Platform!

Leave A Comment

Recent Posts

Tags

Categories

Contact Info

12345 North Main Street, New York City, NY 555555

Phone: 1-800-555-1234

Email: sales@your-domain.com