Knowledge Base
How do I connect to my database via SSH?
Connecting from a shell account
- To connect to your MySQL database via SSH, you’ll first need your database credentials. You’ll also need access to a terminal.
Mac / Linux: Use the native Terminal
Windows: Use PuTTY to connect to your hosting server
Alternatively, you can log in directly to your web server via SSH and run the command there - Open your terminal or PuTTY
Enter:
ssh [email protected] - Once connected to the server, run the following command (replace the placeholders with your actual details):
mysql -h hostname -u user -p databaseWhere:
hostname – Your MySQL hostname (e.g., mysql.example.com)
user – Your database username
password – Your database user’s password (you will be prompted for this)
database – Your database name - After running the command, you’ll be prompted to enter your database password.
Once authenticated, your prompt will change to:mysql>Note: You cannot use localhost to connect, as the MySQL servers are separate from the website servers.
MariaDB MySQL client on private servers (VPS)
If you are using a VPS, the MySQL client is typically MariaDB. All MySQL commands work the same, the only difference is the welcome message shown when you connect.
Example:
mysql -h hostname -u username -p database
Sample output:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 38309156
Server version: 5.7.28-log Source distribution
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [database]>
You are now successfully connected to your database and can run MySQL commands as usual.
Troubleshooting SSH MySQL Connections
| Error Message | Cause | Solution |
| Connection refused | Firewall blocks port | Open port 3306 |
| Host not allowed | Wrong hostname | Use correct hostname |
| Authentication failed | Wrong credentials | Check username/password |
Note: You must use your server’s hostname, not localhost
Did you find this article helpful?