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

  • Posted October 24, 2019
  • MySQL

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:// 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*               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?


Submit an 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,, but it’s easy to check both for whatever sservice it is you’re testing:

mysql -h -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:

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

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