If you are an advanced user, you may wish to use SSH to access and make changes to your account, as it offer a more robust set of options with less limitations. For this, you need to have a basic idea about SSH.
Steps to Import Your Database from the Command Line:
Note: Make sure your database file is in .sql format, it cannot be compressed in a .zip or .tar.gz.
- At first, login to SSH upload your database to your home directory (You can do this using cPanel File Manager, an FTP client, or SSH).
- In case the database isn’t available, please create a database, a user, and give the user complete privileges to the database. Take a note of the username and password.
- Then log into your server using SSH.
- With the ls -l command, verify that the file is present in your current directory.
- In case the file isn’t available, upload/move the file to the correct directory, or go to the directory where the file is located.
- Enter the below command and replace ‘user_name’, ‘database_name, and ‘file.sql’ with your username, database name and file:
mysql -p -u user_name database_name < file.sql
- You will be asked for your database user password, and then your database will be imported.
Steps to Export Database from the Command Line
- Open the command line on the computer where the database is stored. For example, if your database is on another web hosting account or with another web hosting provider, use SSH and log in to the account. In case you have physical access to the computer, open a DOS or terminal window to access the command line.
- Type the below command, and then press Enter. Replace username with your username, and dbname with the database name that you want to export:
mysqldump -u username -p dbname > dbexport.sql
Note: In this example, the dbexport.sql filename is used for the exported database, but you can name the file with the one you want.
- Enter your password at the Enter password prompt.
- The dbexport.sql file now comprise of all the data for the dbname database. If the dbexport.sql file is located on a remote computer, download the file to your local computer.
In this way, you can import and export your database via command line.
Also Read:
How to Import and Export the MySQL Database with phpMyAdmin?
MySQL Database Import Is Failing, Reason: The .sql File Is Too Big