Page MenuHomePhabricator

I can't connect to Toolforge DB replicas from my PC using MySQL Workbench
Open, Stalled, MediumPublic

Assigned To
Authored By
MBH
Mar 23 2024, 5:18 AM
Referenced Files
F43520859: image.png
Mar 27 2024, 1:36 PM
F43118457: image.png
Mar 23 2024, 5:18 AM
F43117262: image.png
Mar 23 2024, 5:18 AM

Description

This manual says a toolforge user can connect to DB replicas using MySQL_Workbench: https://wikitech.wikimedia.org/wiki/Help:Toolforge/Database#MySQL_Workbench
I have used this method in ~2016 and it worked, but after that I didn't used it to 2024.

Now I tried to use it again: I created connections to ruwiki and ukwiki using this manual:

image.png (469×851 px, 40 KB)

I had written this to my C:\Windows\System32\drivers\etc\hosts

127.0.0.1 ruwiki.web.db.svc.wikimedia.cloud
127.0.0.1 ukwiki.web.db.svc.wikimedia.cloud

I opened both connections in MySQL Workbench (and got this warning)

image.png (290×355 px, 15 KB)

I runned PuTTY ssh connection to Toolforge, runned a bot in a local IDE for debugging and it crashed on second line

var ruconnect = new MySqlConnection(connection string);
ruconnect.Open();

with message

SocketException: The connection has not been established because the destination computer rejected the connection request 127.0.0.1:3306

All used logins/passwords/key files are valid, because I have successfully used it to connect to Toolforge using WinSCP and PuTTY now, also I have used the same key file in 2016 to successfully connect to DB replicas, and I don't changed my keys since that.

@dcaro maybe you can say something about it? Maybe there are another method how can I debug my bot on local PC, if it uses DB replica connection?

Event Timeline

The instructions are only for mysql workbench, as in, only mysql workbench will be the one connecting, not your local code.

To connect your local running code to the replicas databases you have to follow https://wikitech.wikimedia.org/wiki/Help:Toolforge/Database#Connecting_to_the_database_replicas_from_your_own_computer, specifically the tunnels setup shown there.

dcaro changed the task status from Open to In Progress.Mar 25 2024, 10:02 AM
dcaro claimed this task.
dcaro triaged this task as Medium priority.
dcaro edited projects, added Toolforge (Toolforge iteration 07); removed Toolforge.

Okay, I probably forgot that it's needed to set up the tunnel in PuTTY settings, and it seemed to me that MySQL Workbench creates tunnel for my app. But I set up tunnel in PuTTY according to manual:

image.png (442×452 px, 27 KB)

loaded key file, opened connection, entered name and password, successfully entered to Toolforge - but bot still can't connect to DB.

Also I can't just create a second tunnel, to ukwiki, not ruwiki, if I don't change 4711 to 4712. The manual says I should replace 3306 to 3307 and so on, but it doesn't help, but replacing 4711 to 4712 for second tunnel helps. Will it work with 4712, should I also replace 3306 to 3307 for second tunnel, according to manual? And what means number 4711, I don't see it in another connection manuals (unlike 3306).

loaded key file, opened connection, entered name and password, successfully entered to Toolforge - but bot still can't connect to DB.

What is the error that you get? Are you configuring the right port in your code/client? (in the screenshot, you are listening on local port 4711).

Also I can't just create a second tunnel, to ukwiki, not ruwiki, if I don't change 4711 to 4712.

Yep, as you already have a tunnel open on your local port 4711, you have to choose another port for the new tunnel that's not being used.

The manual says I should replace 3306 to 3307 and so on, but it doesn't help, but replacing 4711 to 4712 for second tunnel helps. Will it work with 4712, should I also replace 3306 to 3307 for second tunnel, according to manual? And what means number 4711, I don't see it in another connection manuals (unlike 3306).

That part of the manual is for ssh based tunnels (not PuTTY, but the ssh client in the terminal), it's the same yes, just choosing the local port the tunnel will listen in.

If you use 3306, then you don't have to specify a custom port in your configuration/code (as that's the default), but only one tunnel can be in the same port at the same time.

The error looks like the same: The connection has not been established because the destination computer rejected the connection request 127.0.0.1:3306
I'm not configuring port in my code/client and does't even know how to do it, I use the same connection string that on Toolforge: Server=%project%.web.db.svc.wikimedia.cloud;Database=%project%_p;Uid=s52321;Pwd=///;CharacterSet=utf8mb4;SslMode=none;

I remember in 2016 this method works.

computer rejected the connection request 127.0.0.1:3306

You are using the default port there, that's the issue, so you have two options:

  • Configure a different port in your code (maybe by reading an environment variable, or similar)
  • Open the tunnel on your local port 3306, instead of 4711

@MBH were you able to setup the tunnel properly?

I don't and I won't be able to try until May 6, I'm not at home.

okok, let me know when you do :)

dcaro changed the task status from In Progress to Stalled.Tue, Apr 30, 9:45 AM