Connect MySQL database with DBeaver through SSH

Aim:

The aim of this post is to create a straightforward tutorial how to connect to a server MySQL database with DBeaver through SSH.

Prerequisites:

  • DBeaver (version 5.0.1) has already installed natively to Your PC (I used Manjaro)
  • Ubuntu 16.04 VPS (e.g. DigitalOcean) which has a LAMP or LEMP installation
  • Root privilege on Your VPS
Step 1: allow remote access to MySQL

Open a terminal application and login to Your VPS at first via SSH:

 ssh -i PATH_OF_THE_PRIVATE_KEY USERNAME@SERVER_IP 

Navigate to ‘/etc/mysql/mysql.conf.d/’ folder and open the MySQL config file ‘mysqld.cnf’ with a text editor (like nano):

sudo nano /etc/mysql/mysql.conf.d/mysqld.cnf

Comment out the line ‘bind-address = 127.0.0.1’. Make sure This like has to begin with ‘#’ like this:

# bind-address = 127.0.0.1

Save the file and exit (CTRL+X and press ‘Y’ for yes).

Restart the MySQL server to make the changes come into effect:

sudo systemctl restart mysql
Step 2: Allow connection to the mysql port through UFW

For security reasons the best way is just to gain access only to Your PC’s IP You use:

sudo ufw allow from IP_OF_YOUR_PC to any port 3306
Step 3: Connect to MySQL server in Dbeaver

There are two important windows has to fill it in the right way.

In the ‘General’ window You have to take care of only the ‘User name’ and ‘Password’ fields.

User name: (existing) user name You want to use at MySQL connection
Password: Password of the user You selected before

When You have already filled the required fields click to Next button. After it the second important window appears:

First of all click to the checkbox icon ‘Use SSH Tunnel’ to gain access to the settings. Fields You have to fill in the right way:

HOST/IP: IP of the VPS
User Name: (existing) user name You want to use at MySQL connection (same as on the other page)
Authentication Method: ‘Public Key’
Private Key: Path of the private key on Your PC

If everything has configured correctly when You click to ‘Test Connection’ this message box will appear:

When the test connection works click to the ‘Finsih’ button. After the whole procedure You can connect to any MySQL database which Your user has permission to access.


2 Replies to “Connect MySQL database with DBeaver through SSH”

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.