How to set mysql_protocol_tcp in Objective C Mysql client - mysql

I downloaded Karl Kraft's MySQL source and libraries and built a mysql client lib for iOS 6. It worked beautifully the very first time on the local mysql database. Even handled blob data nicely.
The next step was to port forward to a remote database. After downloading various libraries and tearing out my hair, I went looking for a packaged solution.
I downloaded Chilkat's SSH Tunnel library (free 30 day trial -- and $149 -- worth it all). That worked the first time too. It was a pleasure after days and daze of not building, not linking, not compiling, not finding symbols for i386 blah blah blah!!
OK, so here is the kicker. I now want to work with a remote database. When I did the 3306 ssh port forward through ssh port 22 to 3306 on a database machine behind the firewall. Now I turn off mysqld, and my host is localhost port 3306. I have a slight problem with mysql.
The default start of the client on a UNIX/MAC machine is looking for a socket connection on localhost.
I get the following error:
Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (38)
I need a TCP protocol start option for mysql. With a command line, it is easy --protocol=TCP.
With the iOS client lib, it is not readily apparent. I did a search and in the mysql.h we have the mysql_protocol_type and the constants MYSQL_PROTOCOL_DEFAULT, MYSQL_PROTOCOL_TCP etc etc.
The missing knowledge that I have, is how to set the option programatically in Objective C.
There is a server object that just defines the parameters (server, name, ports, username, password) and the next object is a connection object that calls mysql_init(). Does anyone have any clues on how to do this?
BTW: Karl Kraft and the guy from ChilKat should have their blood preserved for posterity. They saved me a lot of time.
Thanks in advance.

Took me a while to figure this out. With the MySQL client, if you specify connection to 'localhost', it tries to connect with a UNIX socket at either /tmp/mysql.sock or /var/lib/mysql.sock. However if you specify localhost as 127.0.0.1, then it connects with a TCP protocol equivalent to --protocol=TCP.

Related

Emulating MySQL Workbench "standard TCP/IP over SSH" from the command line

MySQL workbench has a handy connection option - 'standard TCP/IP over SSH'. This allows me to connect to a publicly-inaccessible MySQL server (let's call it mysql#private.com), by SSH-ing onto a remote server (let's call it myserver#public.com) that is on the same network as the MySQL server.
I am trying to re-create this using the MySQL command line client and persistently failing. I have tried opening an SSH tunnel to forward port 3306 from myserver#public.com, to 127.0.0.1 (ie, localhost). This does not work, because at no point have I specified where to find mysql#private.com.
I presume MySQL workbench must pull off this handy trick via some combination of the MySQL client CLI and generally-availble tools like SSH. If anyone could show me how it's done, I'd be most grateful.
As is customary with SO I googled for about three hours before posting this question then found the answer within about three minutes of posting it. There is a detailed guide here:
https://medium.com/#deepspaceprog/how-to-connect-via-ssh-to-an-amazon-rds-instance-running-postgresql-5e7661cdd37e
That says it better than I can but the critical command is this:
ssh -N -L 3306:mysql#private.com:3306 myserver#public.com
If I paraphrase this into English, I believe it might say
"ssh into myserver#public.com; forward port 3306 on the local connection mysql#private.com to 3306 on the local machine".

Cannot connect remotely to my SQL server remotely

Well, first off, I am no programmer. I am a medstudent with decent computer knowledge, and that has done this at least one time before in his home network.
Now, i am doing some research at the hospital, and for my database i want to use mysql, running a server on a local network computer and being able to connect to it from laptops over wi-fi to work on the database.
So i download mysql installe, run it, and i connect via localhost perfectly well with the root acc or the set up accounts i will use. I do bind-address to change its ip to the computers IP on the network, and i can connect again with root and with my accounts perfectly well on the machine the same server is on, using xx.xx.xx.xx + port to connect, with root and all other users.
however, using workbench on a laptop connected to the local network, I cannot connect with any user, it always gives error 10060.
--Firewall is off
--All AV software is off
--accounts are set up correctly to allow connection from any host
--client PC can ping server PC
--Netstat -anob shows mysqld.exe listening on the port i need it to be listening
The network here does block connections, but the port im using is open due to the fact it is used for another server type application that as very little to no traffic, so i just grabbed the opened ports for that application as they showed up in netstat and configured te server to use one of those ports.
How can i make sure the server PC is open at those ports?
THe client im trying to connect with is either the mysql workbench or heidisql.
Neither can connect, however i have succesfully used heidi before to connect to a database I have in DB4free.net. I cannot use that at the hospital, because the network shuts off the default port for mysql which is what db4free.net uses.
Any ideas why i cant connect to that PC?
mySQL often does not come configured for remote connections by default. The port may be open, but if mySQL isn't listening or is set to reject all remote connections, you won't be able to connect.
Check the documentation for your version of mySQL to find out how to modify your mySQL server's configuration to allow remote connections.

How to fix 'Can not connect to MySQL server' error?

First of all I apologize for my English is not perfect.
I'm trying to connect to mysql database remotely.
I have already done the basic steps such as, for example, comment the bind address in my.cnf.
I gave permissions to the appropriate users in MySQL.
I tried with my friend to do it connect to the database, and it worked but we were in the same room with the same router.
Now I'm home and I tried to connect my friend, but I always get error:
ERROR 2003 (HY000): Can not connect to MySQL server ....
Maybe it's a problem of my home router? I can not even do the telnet.
P.S. I've also taken steps to set the firewall.
Some reasons for that,
mysqld is not running on the local host. Check your operating
system's process list to ensure the mysqld process is present.
You're running a MySQL server on Windows with many TCP/IP connections
to it. If you're experiencing that quite often your clients get that
error, you can find a workaround here: Section B.5.2.2.1, “Connection
to MySQL Server Failing on Windows”.
Check whether the server is running on that host by executing telnet
some_host 3306 and pressing the Enter key a couple of times. (3306 is
the default MySQL port number. Change the value if your server is
listening to a different port.) If there is a MySQL server running
and listening to the port, you should get a response that includes
the server's version number. If you get an error such as telnet:
Unable to connect to remote host: Connection refused, then there is
no server running on the given port.
Look at this mySQL full documentation, it will be helpful.

MySQL does not work on localhost without Local Area Connection

I use WampServer (Apache, PHP, MySQL) and have no problems when some kind of network adapter(wireless or lan) is connected (i.e. Local Area Connection has status connected) even if i am not connected to the internet (for example when i am connected to the router but that is not connected to the internet).
When there is no network connection, I get a php error like MySQL could not connect to 127.0.0.1 on port 3306.
Interestingly, telnet 127.0.0.1 3306 says that it could not connect to the port, even when the server and MySQL are running fine (i.e. when some kind of local area connection is connected).
So I turned off all kinds of firewall (antivirus and Windows) but still no difference in anything. And that is why this issue is quite puzzling.
Things I have already tried (will update this list along the way):
The skip-networking directive in my.ini.
You could modify your MySQL server and client configuration to connect to one another using a named pipe instead of a TCP/IP loopback connection. That way, the current state of the network connection should have less impact.
To do so, start the server with --enable-named-pipe or the corresponding config file setting, and execute the client with --pipe or --protocol=PIPE. Similar configurations should be available for your PHP connector as well. It may depend on which library you use there, and whether or not it will take the mentioned configuration settings from the my.ini file (settings without leading -- there).

Connecting to remote MySQL problems

Having a bit of a problem with mysql...
Mysql 5.1 on windows 2008 server iis7
Site on windows 2003 server iis6
[sorry but can't move to linux kids! ;)]
In the process of shifting a site to a new server so I have moved the database 1st and connected the site to the new database. I tested the connection before moving but now the site is connecting to the new database I am having problems....
connecting via PDO the page hangs for an age before getting 'too many connections' error. Monitoring the server I see MANY threads of: 'unathenticated user' from the ip address of the host the site runs on.
I also see a thread for the connection with the correct user name in my config file and I am a total loss as to what is going on.
Any help would be very much appreciated
'unathenticated user' from the ip address of the host the site runs on
A stab in the dark, but this could be some script or process trying to connect to the database server with wrong or empty credentials.
Also, here's a report from somebody who had similar problems - in that case, it was the DNS lookup that caused the problem.
I had a similar situation on my setup where the database lived on a different host than
the webserver. I found the "unauthenticated users" were connections from the webserver
that were hanging on DNS lookups. Don't know if this is a mysql bug or a bug with my
firewall / other setup, but a couple of fixes I found were...
1) start mysql with --skip-name-resolve (you may have to change your mysql permission
tables to have the host's IP instead of hostname, including localhost)
or 2) add the connecting host to your /etc/hosts file.