Export/Import Mysql database using SSH in Godaddy and other Server

Published On: 29 May 2012.By .
  • Digital Engineering

Export Mysql Database

How to take the back up of Mysql database using SSH –

  • Enable shell access inside your Plesk control panel
  • Using utility such as PuTTY, log into your server via SSH
  • Change to the directory where you want to save your backup files — e.g., CD wwwroot/dbbackup. If you don’t have a directory created, follow these steps:
    • FTP into your server, using software such as FileZilla Client
    • Go to your domain root directory
    • Create a folder — e.g., call it dbbackup
    • CHMOD the dbbackup folder attribute to 777
Following is the command line used in SSH to backup/export mysql database from SSH –

mysqldump –add-drop-table -h db_host -u db_username -p db_name> db_backup.sql

or

mysqldump –add-drop-table -u db_username -p db_name> db_backup.sql

  • Enter the Database password when prompted
  • –add-drop-table – Omit this argument if you want to merge this backup with an existing database upon restore
  • Replace db_username with the name of your database user
  • Replace db_name with the name of your database
  • Replace db_backup.sql with the name of your backup file
  • db_host – This is only required if the Database host is different from Localhost. In most cases the host name is not required as the files and database are stored in the same server. So you can skip -h db_host
  • But if you have Godaddy Shared Hosting account then the files and Mysql Database are stored in separate server. Godaddy Sever name would be like: dbname.db.6098394.hostedresource.com

 Import Mysql Database

The file must be in .sql format. It can not be compressed in a .zip or .tar.gz file.

  1. Start by uploading the .sql file onto the Bluehost server
  2. If you haven’t already done so, create the MySQL database via the cpanel. Click Here for further instructions
  3. Using SSH, navigate to the directory where your .sql file is.
  4. Next run this command: Note: The -p will prompt for your account’s password.

    Note: username is the user with rights to the database. If you are unsure what the username is you can use the same username and password used to sign into SSH.

    Note: Make sure your database name has your host username prefix with the _ (underscore) after it and the database name.

 

 

Related content

That’s all for this blog