Loading...

Knowledge Base

How to Import and Export MySQL Database Using SSH

MySQL is a widely used open-source relational database management system for web applications. If you need to import or export MySQL databases, you can connect to your server using the SSH protocol and execute the necessary commands.

SSH or Secure Shell is a network protocol allowing secure computer communication. It is a powerful tool that can help you easily manage your databases on Bluehost your account. You can learn how to import and export a MySQL database using SSH with a straightforward command.

If you cannot access SSH currently, refer to our article What is SSH Access and How to Enable It in Your Hosting Account, which provides step-by-step instructions on how to set up SSH access on Bluehost your account.



In all examples below, the -p will prompt for your account's password. Make sure your database name has your BRAND username prefix with the _ (underscore) after it and the database name.

To import and export MySQL using SSH, follow the steps below. Alternatively, if you prefer to use phpMyAdmin, we have an article on How to Import or Export a MySQL Database using phpMyAdmin.that provides instructions on importing or exporting a MySQL database. Using phpMyAdmin makes it easy to manage your MySQL databases.

How to 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 control panel. Click here for further instructions.
  3. Using SSH, navigate to the directory where your .sql file is.
  4. Next, run this command:
    mysql -p -u username database_name < file.sql

To import a single table into an existing database, you would use the following command:

mysql -u username -p -D database_name < tableName.sql

When importing MySQL using SSH, there are no size limits as such. However, the import process may take longer for larger files and may also depend on your server's resources. It is recommended that compression techniques, like gzip, be used to reduce the file size to be imported. Additionally, it is important to make sure that the server has enough disk space to handle the import file and that the database user has sufficient privileges to perform the import.

How to Export MySQL Database

This example shows you how to export a database. It is a good idea to export your data often as a backup.

  1. Using SSH, execute the following command:
    mysqldump -p -u username database_name > dbname.sql
  2. You will be prompted for a password, type in the username and password, and press Enter. Replace username, password, and database_name with your MySQL username, password, and database name.

The file dbname.sql now holds a backup of your database and is ready for download to your computer. To export a single table from your database, you would use the following command:

mysqldump -p --user=username database_name tableName > tableName.sql

Again, you must replace the username, database, and tableName with the correct information. Once done, the table specified would be saved to your account as tableName.sql.

Summary

MySQL is a widely used open-source database management system for web applications. Learning how to import or export MySQL database using SSH or phpmyAdmin is essential for managing. SSH is a powerful tool that can help you achieve that. In this article, we have provided step-by-step instructions on how to import and export MySQL database using SSH on a BRAND hosting account. However, if you prefer phpMyAdmin, refer to our article on How to Import or Export a MySQL Database using phpMyAdmin.

Whether you use SSH or phpMyAdmin, managing your databases on Bluehost, your account can be easy with these tools.

If you need further assistance, feel free to contact us via Chat or Phone:

  • Chat Support - While on our website, you should see a CHAT bubble in the bottom right-hand corner of the page. Click anywhere on the bubble to begin a chat session.
  • Phone Support -
    • US: 888-401-4678
    • International: +1 801-765-9400

You may also refer to our Knowledge Base articles to help answer common questions and guide you through various setup, configuration, and troubleshooting steps.

Did you find this article helpful?

 
* Your feedback is too short

Loading...