I try to connect to my MySql database with c++ but it won't connect and I cant figure out why. The Instance of the MYSQL object was initialised and I also tried to connect to my database with Java and Php and it worked...
The Mysql server is not hosted by me, it's hosted by an German server provider so I suggest on the server side will be everything ok.
Also the libs and includes are linked correct since the initialisation of my MYSQL instance works fine.
The mysql version I use is 5.0.X
this is the line of code where I try to connect to the database:
MYSQL *connect = mysql_init(NULL);
mysql_real_connect(connect, "xxxxx.db.1and1.com", "dboXXXXXX", "XXXXXX", "dbXXXXXX", 0, NULL, 0);
Related
I am working on a server application in c++ that will connect to a MySQL Server using MySQL Connector/C++ 8.0.
The server has X plugin disabled and I cannot change that.
https://dev.mysql.com/doc/refman/8.0/en/x-plugin-disabling.html
It is possible to connect to this server using MySQL Connector/C++ 8.0 ?
I found nothing in the docs.
I have tried to modify the protocol in the session connection string from mysqlx:// to tcp:// but my config supports only mysqlx.
There is something I am missing the connection is possible only using MySQL Connector/C++ 1.x ?
The error I am receiving is CDK Error: unexpected message. I can successfully connect to a local MySql database instance.
Looking at the question tags, I guess you are using Amazon RDS and, as far as I can tell, at the moment, Amazon RDS does not support the X Plugin and consequently does not support X Protocol connections (mysqlx:// on port 33060 by default).
However, Connector/C++ also supports JDBC and whatnot, so you should be able to connect to any MySQL instance on port 3306 as well.
Disclaimer: I'm the lead developer of the MySQL X DevAPI Connector for Node.js
I am developing a test app to understand how to do SSH tunnelling to connect to a MySQL Database in C++.
I am using the libssh2 library and I am using an example from https://www.libssh2.org/examples/direct_tcpip.html but I am not 100% sure whether or not this is the correct thing to use.
I've pretty much copied the example but when connecting to MySQL on my socket, MySQL throws:
Errro 2013 (HY000): Lost connection to mysql server at 'reading communication packet', system error: 0
When I connect to mysql using mysql -uroot -p -P2222 my app reads data on the channel using the following:
int len = libssh2_channel_read(channel, buf, sizeof(len));
and the buf contains SSH-2.0- and then this is written to the forwarding socket as follows:
wr = 0;
while (wr < len)
{
i = send(forward_socket, buf + wr, len - wr, 0);
if (i <= 0)
{
perror("write");
return EXIT_FAILURE;
}
wr += i;
}
As soon as the send is done, I instantly get the mysql error. I assume it is because I am sending SSH-2.0- to MySQL which MySQL isn't expecting so its closing the connection but I can't see what's wrong, and I can't find for certain whether or not libssh2 direct_tcpip is the correct thing to use.
Finally, managed to figure out what to do, with lots of trial and error and hair pulling managed it.
Using the example from https://www.libssh2.org/examples/direct_tcpip.html but I was setting the variables with the wrong value.
Basically, in the example it has
const char *remote_desthost = "localhost"; /* resolved by the server */
unsigned int remote_destport = 22;
Because of remote_destport in the example being 22, I thought this was the SSH connection details so I set this to be my SSH settings.
It turns out this is where the connection gets forwarded to from the SSH session so I changed it to be
const char *remote_desthost = "localhost"; /* resolved by the server */
unsigned int remote_destport = 3306;
So now I can run my app from my laptop, which connects to my SSH server for my web server and then on my laptop run in the command
mysql -uroot -p -P2222 and I connect to the database on my webserver through the SSH tunnel.
I think you have misunderstood what SSH Tunnelling is.
SSH Tunnelling is nothing more than a Client Socket to Server Socket Mapping E.G a Firewalled Network port.
And to show that this is how it works. i used my personal web server and connected to a MySQL server that does not allow any external connections to it so connections from localhost only.
To Setup a SSH Tunnel using LibSSH2 follow the code at http://api.libssh.org/master/libssh_tutor_forwarding.html under heading Doing direct port forwarding with libssh
If you don't want to expose the mapping to a port on your client machine you don't necessarily have to you could manually send data down the channel and read it however if there is any form of encryption or text encoding that does not match your on the channel to mysql you will send invalid data to it.
So once you have SSH Tunnelling created then you use it as a standard network connection to the port you have Tunnelled to talk to the service if you wish to do this in C++ use the MySQL C++ Connector and once the tunnel is create connect using the C++ Connector.
If you wish to allows your application to talk to MySQL though the SSH channel without exposing it to a network port, you probably gonna have to mess with the source code for the C++ MySQL Connector. A lot, more work that you think it is you would be going though the entire connector and any writing and reading it does via the Network Socket and replace it with code to go though your SSH Tunnel Channel.
Referring to Pentaho's Doc, we should be using RedshiftJDBC4.jar instead of version 4.1. I have downloaded the driver and placed it in the lib/ directory. Relaunched spoon.sh and I noticed it is no longer complaining about not able to find the com.amazon.redshift.jdbc4 class driver as I was using the 4.1 driver earlier. However, it still could not establish the connection.
Error connecting to database [aws_redshift] :
org.pentaho.di.core.exception.KettleDatabaseException: Error occurred
while trying to connect to the database
Error connecting to database: (using class
com.amazon.redshift.jdbc4.Driver) Amazon Error setting
default driver property values.
Can anyone help on this?
On the flip side, I can connect to my endpoint using SQLWorkbench/J, a SQL client tool.
Somehow I managed to get it working. It seems that downloading AWS Redshift drivers version 4, 4.1, or 4.2 and placing them in the lib/ directory did not work for me for each version by choosing Redshift as connection type (in Database Connection setup).
Instead, I chose PostgreSQL using JDBC. In host name field, I included the endpoint WITHOUT port number 5439 at the end. So, the endpoint should just end with ...amazonaws.com. Fill in database name, port number of 5439, and username and password. If this did not work, try downloading the latest PostgreSQL JDBC driver and placing it in lib/ directory and try again.
I am new to database programming.
I am trying to make an application that interacts with a database file locally so that I can use those database query.
I tried to use mySQL connection c++ 1.1.6, and run this example.
Following error is what I get:
MySQL server on '127.0.0.1' <10061> <MySQL error code: 2003, SQLState:>
I guess that I need to have a server on for connecting. What I want is just an interaction with a database file locally, do I need to make this connection also? If I really need this connection, how to make it works?
I writing a c++ program that should connect to a mysql database.
it works successfully when I use the local database, but I get an error
"Can't connect to mysql database on '192.168.0.111' (111)"
when I try to connect to a database on another computer.
this is the function that test my connection:
void addb()
{
string mainServer="192.168.0.111";
string mainDbUser="root";
string mainDbPass="111";
MYSQL *connect; //database connection variable
connect=mysql_init(NULL);
if(!connect)
cout<<"Couldn't initiate connector\n";
if (mysql_real_connect(connect, mainServer.c_str(), mainDbUser.c_str(), mainDbPass.c_str(), "main" ,0,NULL,0))
{
cout<<" done\n";
}
else
{
cout<<mysql_error(connect)<<endl;
}
mysql_close (connect);
}
both computers are running Linux Mint OS.
I tried disabling my firewall on the second computer but i got the same problem.
note: I can access the database using phpmyadmin with my web browser.
Make sure the firewall allows MySQL port on the DB machine.
Make sure in the my.cnf the database is loaded with you have the proper network configuration (to listen to the public IP).
From the error message - I would suspect it is a firewall issue - so make sure the DB machine firewall allows incoming communication (and specifically - that SELinux enables it in addition to the firewall) and that the sending machine allows outgoing communication to this machine.