Problem
I'm following tutorial on Connect/C++ provided by dev.mysql. After copying the example and successfully compiling and linking it, I run into following issue:
terminate called after throwing an instance of 'sql::SQLException'
what(): Can't connect to MySQL server on '127.0.0.1' (111)
From what I know 111
stands for Permission Denied.
Setup
Here is the example code taken from here and slightly modified:
#include <mysql_driver.h>
int main()
{
auto driver = sql::mysql::get_mysql_driver_instance();
auto con = driver->connect("tcp://127.0.0.1:0", "root", "123");
delete con;
}
Trying with tcp://127.0.0.1:3306
give the same result.
Here is the CMakeLists.txt:
cmake_minimum_required(VERSION 3.9)
project(mysql_try)
set(CMAKE_CXX_STANDARD 14)
set(SOURCE_FILES main.cpp)
add_executable(mysql_try ${SOURCE_FILES})
target_include_directories(mysql_try PUBLIC /usr/local/include/mysql++)
target_link_libraries(mysql_try mysqlclient /usr/local/lib/libmysqlcppconn-static.a pthread dl)
I can easily run mysql
with the credentials in the code. I disabled networking, so that it would only listen on localhost
. Running
mysql> SHOW GLOBAL VARIABLES LIKE 'PORT';
gave me 0, so I guess it is port 0.
C Connector and command line interfaces work just fine.
My OS is ubuntu 16.04.
mysql
and perform queries.0
? Are you sure that's correct?port
.