How To Import Or Export Database Through SSH

A designer sometimes comes across the problem, where the database is too large to be imported through phpmyadmin. Phpmyadmin allows usually only maximum 50M database size. If your database is larger than that, you can use putty, cmder, or gitbash. I mean every CLI works pretty much.

I prefer to use cmder. It is a small program and it works.

I have to post some notes about this process, because it isn't easy. You need to also enable SSH on your hosting account, talk to host support, they will help you out. 

Then you conect to your server via this command

ssh username@domain      for example     ssh seoninja@seoandwebdesign.com     where seoninja is the hosting username

Then just use these commands inside putty.

ls  --     list all directories where you currently are inside putty, and your server

cd go directory up

cd public_html  -  for example, this command puts you inside the public_ html folder, where you can upload our database.sql file that you want to import with putty.

IMPORT DATABASE

First step is to create a database inside your phpmyadmin section of your cpanel.

So go to your cpanel and select databases. Create a database and assign a database user, grant him all rights. If you already have a database you can skip this step.

Then use the following command:

mysql -p -u username database_name < file.sql

mysql -p -u johndoe johndoe_vivacedatabase < vivace.sql

On my host you need to place the database with the same name into home directory, that is directory above public_html. So place your database there in this case vivace.sql. Then run the above command. Your database should be imported.

EXPORT DATABASE

When you export check your database name, username and password (Wordpress check wp-config.php  in Drupal check settings.php file)

Then use this command

mysqldump -u username -p database_name > dbname.sql

It will ask you for password, here you input the database password you read before.

The database should be in your home directory on your server. Use ftpzilla for example to download it.

I did not know regarding Putty, often I faced problem with large database size, I will try myself wish me luck. Your instruction is clear and easy to follow, If someone would follow , I could appreciate you. Thanks for sharing.

Add new comment

The content of this field is kept private and will not be shown publicly.

Plain text

  • No HTML tags allowed.
  • Web page addresses and email addresses turn into links automatically.
  • Lines and paragraphs break automatically.