Report this

What is the reason for this report?

Does digital ocean prohibit tcp connections to localhost on a mysql server?

Posted on October 24, 2019

I am trying to connect to a database with a c++ program. I am using the mysqlcppconnector with the connection strings tcp://localhost:3306 and tcp://127.0.0.1:3306. The program works on my local machine, but when I try to run it on my digital ocean Ubuntu server after ssh’ing in, it complains:

terminate called after throwing an instance of 'sql::SQLException'
  what():  Unknown MySQL server host 'tcp' (2)

I have tried many ports, including the default of 3306. I can also connect to the database outside of c++, manually on the command line, by typing in mysql -u root -p. After that, I can type show variables; and indeed I see skip-networking set to “OFF”, which is what it should be. Finally, MySQL appears to be listening on the network:

netstat -a | grep mysql
tcp        0      0 localhost:mysql         0.0.0.0:*               LISTEN
unix  2      [ ACC ]     STREAM     LISTENING     20025    /var/run/mysqld/mysqld.sock

Is there some configuration that I forgot to change? What does the “(2)” mean?



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

DigitalOcean does not prohibit tcp connections to localhost.

The netstat output you provided does look like it is bound to localhost and listening on the “mysql” port - which is the default 3306. To see a little clearer info, you can run netstat -an which will use IP addresses and port numbers instead of domains / services.

Just to confirm you can access mysql via CLI to localhost, let’s try running this command:

mysql -h localhost -u root -p

I usually use the IP address, 127.0.0.1, but it’s easy to check both for whatever sservice it is you’re testing:

mysql -h 127.0.0.1 -u root -p

If both of those work, you might try comparing the versions of mysqlcppconnector that you are using locally and on your Droplet. I found some hints here:

https://unix.stackexchange.com/a/548725

That answer links to another question with more info, too.

Hope this helps! Let us know if you need additional help or advice.

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.