How to import an SQL file via command line

By Angus Published 20 December 2024 Updated 19 February 2026 3 min read

phpMyAdmin’s upload limit prevents you from importing large SQL files directly through the interface. The command line bypasses this restriction and allows you to restore databases of any size.

You will connect to your server via SSH, navigate to your SQL file and run a single command to import it into your MySQL or MariaDB database. This method works for database backups, site migrations and restoring data after failures.

Before you begin

  • You need SSH access configured on your hosting account.
  • Your SQL file must be uploaded to an accessible directory like /home/user/ or /home/user/public_html.
  • We recommend creating a backup of your existing database before importing new data.

Import the SQL file

You will log into your server via SSH, navigate to the directory containing your SQL file and run the import command. The process completes in seconds for small files and may take several minutes for larger databases.

  1. Connect to your server via SSH.
    Open your SSH client and connect using your hostname or IP address, username and SSH key. If you are using PuTTY, enter your connection details in the Session category and click Open.
  2. Navigate to the directory containing your SQL file.
    Use the cd command to change to the directory where your SQL file is stored. For example, if your file is in public_html, run cd public_html. This makes the import command shorter and reduces the chance of path errors.
  3. Run the import command.
    Execute mysql -u username -p database < mysql_file.sql, replacing username with your database username, database with your database name and mysql_file.sql with your SQL filename. The -p flag prompts you for your database password.
  4. Enter your database password.
    When prompted, type the password for your database user. This is the password you set in cPanel or Plesk when creating the database user. The cursor will not move as you type, which is normal for password entry in the terminal.

The import runs immediately after you enter your password. You will see your command prompt return when the process completes. Your database now contains the data from the SQL file.

Troubleshooting

Import hangs or times out

Large SQL files may take several minutes to import. If the process appears stuck for more than 10 minutes, press Ctrl+C to cancel and contact support for assistance.

Permission denied errors

Your database user needs appropriate privileges for the target database. Check user permissions in cPanel or Plesk and grant all privileges if necessary.

Strange characters appear after import

Character encoding mismatches cause display issues. Most WordPress databases use utf8mb4_unicode_ci as the collation. Check your database collation in phpMyAdmin and ensure it matches your SQL file’s encoding.

Cannot log into WordPress after import

Imported databases contain the original site’s user credentials. You will need to reset your WordPress admin password to regain access.

Wrapping up

You imported your SQL file into your MySQL or MariaDB database using the command line. This method bypasses phpMyAdmin’s upload restrictions and handles databases of any size. Your database now contains the imported data and is ready to use.

For smaller files under the upload limit, phpMyAdmin provides a graphical interface. You can also split large SQL files into smaller chunks or use alternative tools like Adminer. Our WordPress FAQs cover additional database management topics.

If you run into any trouble, get in touch and our team will be happy to help.

Running a WordPress site?

Get fast, secure and reliable WordPress Hosting with optimised for performance with AccelerateWP.

Get WordPress Hosting

Need multiple accounts?

Create fully isolated individual accounts for your clients and manage them all from one dashboard.

Get Reseller Hosting