If you have enabled SSH access on your hosting package, then you can import a MySQL database easily using command-line tools. This method is quick, reliable and often used for database migrations or backups.
To load a .sql file you have to use the command of MySQL in the terminal.
The usual command to import a database is:
mysql -h hostname -u username -p username < databasefile.sqlThis command will connect to your MySQL database and will import the SQL file directly into it.
In the command above:
-h hostname → This defines the host of the database server (for example, localhost or a remote server address)
-u username → This is your mysql user name
-p → It will safely ask you for your database password
username (database name) → This is the database to which you want to import the SQL file
< databasefile.sql → This tells the system to import data from the given .sql file
You should upload the .sql file first or make sure that it is available in your server directory before running the command.
Before you import, make sure:
The database is already in place
You have valid credentials to the database
The .sql file is not corrupt or half uploaded
If the file is compressed (e.g. .zip or .gz), it should be unzipped before running the import command.
One of the most efficient ways to restore or migrate databases is to import a .sql file using command-line. It offers you direct control, faster execution and is suitable for both small and large databases when used right.