Loading...

Knowledge Base
Hosting Ad
 Up to 70% off  on  WordPress  hosting for WordPress Websites and Stores!
Categories: ,

How to Manage Databases with SSH Command Line

Share

Learning how to manage a database with the SSH command line can seem intimidating at first. Still, it can be a powerful tool once you become familiar with the process.

SSH enables secure communication between two remote machines and can be used to connect to a server that hosts a database. Once you have established an SSH connection, you can use command-line tools to manage your database, including creating and deleting tables, adding and deleting data, and running queries. You can perform these tasks quickly and efficiently using the command line without needing a graphical user interface. In this way, you can manage your database from anywhere, as long as you have an internet connection and access to SSH.


Benefits of Managing Databases

Manage database with the SSH command line has a few benefits:

  • Security: SSH provides a secure way to access the database. All data transmitted between your computer and the server is encrypted, making it much more difficult for hackers to intercept or steal sensitive information.
  • Efficiency: Using the SSH command line allows you to perform database management tasks more quickly and efficiently than using a web-based interface. For example, you can import or export a MySQL database into an existing database on your account with a simple command.
  • Flexibility: SSH gives you more control over your database management tasks. You can execute commands, scripts, and queries directly on the server, which provides you with more flexibility and customization options.

Using SSH to manage a database can be a powerful tool for developers and system administrators who need to manage large amounts of data quickly and securely.

Please see our article on getting SSH access if it has not yet been enabled on your account.

Please note that in the examples below, the -p will prompt for your account's password. And that your database name needs to include your Bluehost username, e.g., examplec_database.

How to Export a 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 password for the username, 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 would need to replace the username, database, and tableName with the correct information.

Once done, the table specified would then be saved to your account as tableName.sql

How to Import a 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 in the control panel. 
  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

Summary

Learning how to manage a database with the SSH command line can initially seem daunting. However, SSH provides a secure way to access your database and enables you to perform various management tasks quickly and efficiently using the command line. With the benefits of security, efficiency, and flexibility, developers and system administrators can manage large amounts of data quickly and securely.

The guide also provides step-by-step instructions on exporting and importing databases and tables using MySQL, along with some notes on naming conventions and file formats. By following these instructions, you can manage your databases from anywhere, as long as you have an internet connection and access to SSH.

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...