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 remote 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'm just trying to connect on localhost, at the default port 3306. I can also connect manually by typing in mysql -u root -p and just logging in that way.

After logging in to my database with mysql -u root -p, I can type show variables; and indeed I see skip-networking set to "OFF".

MySQL is 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?

  • @Christopher root@ubuntu-s-1vcpu-1gb-nyc1-01:~# netstat -a | grep mysql tcp 0 0 localhost:mysql* LISTEN unix 2 [ ACC ] STREAM LISTENING 20025 /var/run/mysqld/mysqld.sock
    – Taylor
    Oct 24, 2019 at 15:39
  • Check the firewall setting too ;)
    – mariaczi
    Oct 24, 2019 at 15:59
  • @mariaczi on the server? how would I bet able to ssh in then?
    – Taylor
    Oct 24, 2019 at 15:59
  • Is How to connect mySQL database using C++ any help? Oct 24, 2019 at 21:24
  • @roaima my code resembles that. But I'm reasonably sure it already works--I have successfully ran the program on my local machine. It connects to a database and writes to it. This error only pops up when I try to run it on my server. I was thinking it's either some default configuration that digital ocean has, or some path that was hardcoded that changes...I'm not sure what it could even be.
    – Taylor
    Oct 24, 2019 at 21:32

1 Answer 1


Thanks everyone for the suggestions. I fixed it by reinstalling mysqlcppconnector (not by changing the c++ code). I started suspecting it was something build-related, so I asked about this here.

A few notes on the differences between the two installations: instead of using 1.1.12, I reinstalled with the most recent edition; also, I didn't install by manually copying files around, I installed with

sudo apt-get install libmysqlcppconn-dev

I don't know if this is a coincidence, but I also notice that clicking on "Looking for previous GA versions?" at the download page doesn't redirect you to version 1.1.12 anymore--it directs you to 1.1.13.

After this the program ran. Well, it did give me an error, but a different one, and the fix for this issue was pretty easy. For what it's worth, it was

Access Denied for User 'root'@'localhost'

I checked the permissions by typing SELECT user,authentication_string,plugin,host FROM mysql.user;, saw that localhost didn't have mysql_native_password permissions (only auth_socket), so I changed that by doing

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'secret_password_here';

Hope this helps someone else--this was a strange one. Thanks everyone for the help, too.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .