Or copy link
Copy link
SSH stands for Secure Shell is a powerful network protocol that enables secure remote access to a computer system. Managing databases through the SSH command line can be a powerful and efficient way to handle your data. It is used by system administrators to manage databases remotely.
In this article, we will understand how to manage databases using SSH covering everything from establishing a connection to performing various database operations.
SSH is a protocol that allows secure communication between two machines. It encrypts the data transmitted between the client and the server ensuring that sensitive information remains protected. SSH is commonly used for remote server management including database administration.
Before getting started let’s understand the SSH fundamentals:
SSH access can connect to the server using the following command:
ssh username@server_ipaddress
Replace username with your username and server_ipaddress with the IP address of your server.
username
server_ipaddress
Unlock the power of Ulta SSH VPS
Buy SSH Full Linux Root Virtual Private Servers with Instant Setup, Our VPS includes a free trial for 30 days, Choose different Linux-based operating systems.
MySQL, PostgreSQL, and Oracle are popular databases. Below we discuss how you can connect both databases with the help of the SSH command Linux:
MySQL is one of the most popular open-source relational databases. Here’s how to manage the SSH MySQL database:
Exporting Databases
Exporting a database is essential for creating backups. Use the mysqldump command to export a backup MySQL database:
mysqldump
mysqldump -u username -p database_name > backup.sql
You will be prompted to enter the password for the MySQL user. Replace username and database_name with your actual MySQL username and database name.
database_name
Importing Databases
To import a database, use the mysql command:
mysql
mysql -u username -p database_name < backup.sql
Again, you will be prompted to enter the password for the MySQL user.
MySQL client configuration
Create a remote MySQL client configuration with the following command:
mysql --defaults-file ~/.my.cnf
Edit the ~/.my.cnf file to store your username, password, and other connection details.
~/.my.cnf
Login MySQL Database
To login to your MySQL database with SSH, type the following command:
mysql -u root
Enter the password if prompted. After that, you can easily log into the MySQL command line interface.
1. Execute SQL Queries
You can easily write SQL queries once you have entered the MySQL interface.
SELECT * FROM your_table; INSERT INTO your_table (column1, column2) VALUES ('value1', 'value2');
2. Creating and Deleting Tables
To create tables in MySQL, run the following queries:
CREATE TABLE table_name ( id INT AUTO_INCREMENT PRIMARY KEY, column1 VARCHAR(255) NOT NULL, column2 INT NOT NULL );
If you want to delete the tables in the MySQL, run the following:
DROP TABLE table_name;
PostgreSQL is another popular open-source relational database. Here’s how to manage it using SSH:
Connect PostgreSQL server
To connect with the PostgreSQL database in SSH, type the following:
psql -U your_username -d your_database
Replace your_username with your actual username and your_database with the real database name.
your_username
your_database
PostgreSQL client configuration
Create a remote PostgreSQL client configuration with the following command:
psql -c "CREATE ROLE your_username WITH PASSWORD 'your_password';"
Edit the ~/.pgpass file to store your username, password, and other connection details.
~/.pgpass
Oracle Database is a commercial relational database system. Here’s how to manage it using SSH:
Connect Oracle server
To connect with the Oracle database in SSH, type the following:
sqlplus / as sysdba
Oracle client configuration
Create a remote Oracle client configuration with the following command:
sqlplus / as sysdba CREATE PROFILE your_profile LIMIT CONNECT_TIME 60; GRANT CONNECT TO your_username PROFILE your_profile;
Edit the ~/.sqlplus file to store your username, password, and other connection details.
~/.sqlplus
Also, Read How to Fix “Connection reset by peer” SSH Error.
When managing databases via SSH security is an important element. Here are some best practices:
Managing databases via SSH command line can be a powerful and efficient way to handle your data. By following the steps outlined in this guide you can securely connect to your server perform various database operations and ensure that your data is well managed and protected. Whether you are exporting and importing databases, creating and deleting tables, or running queries SSH provides a flexible and secure way to manage your databases.
Elevate your business with the Ultahost NVMe VPS server which provides significantly faster data access speeds compared to traditional storage options. This means your website will load faster resulting in a smoother user experience and potentially higher conversion rate.
SSH (Secure Shell) is a protocol used to connect to remote servers to manage databases securely.
Use the ssh command in your terminal followed by your server’s IP address to connect.
Yes, you can use commands like mysql to manage MySQL databases through SSH.
Use the mysqldump command to create a backup of your database.
Yes, SSH encrypts the connection making it a secure way to manage databases remotely.
Yes, you can restore databases using commands like mysql < backupfile.sql.
SSH offers secure and remote access to manage your databases without needing a graphical interface.
PostgreSQL, also known as Postgres is a powerful open-s...
Authentication plays a pivotal role in upholding securi...
In today's interconnected world, having a secure and pr...
phpPgAdmin is a free, web-based interface for managing ...
Telnet short for Telecommunication Network is a network...
In today's digital world, ensuring secure communication...
Save my name, email, and website in this browser for the next time I comment.
Δ