I am using c to communicate with mysql
it uses mysql_real_connect() to connect to DB engine.
I am just curious about knowing "why this function require socket name and port number both?".
Can we not use only port number to communicate with mysql.
I googled for it but couldn't find any answer.
Sorry for such a childish question.
If you are using named pipes or domain sockets then the socket name specifies the pipe or socket name. Otherwise, you can just pass 0 as the name.
You don't, obviously. You supply one or the other, depending on the protocol chosen by the value of the 'host' parameter, as described in the document you cited.
Related
I have a situation, where I have a computer with multiple IP's, the computers primary IP will never change, but all the secondary IP's will.
I connect to a remote MYSQL computer and I have access granted based on my IP address. Sometimes, my PC likes to select one of the secondary IP's.
I looked in to the "Set As Source" flag and tested that solution, but what happens is, that I can't select those extra IP's for outbound communication.
Dim IPS As IPAddress() = Dns.GetHostAddresses(Dns.GetHostName())
Any IP with the "set as source" = false - won't be returned with the above code.
So how would I get around this dilemma? I can't seem to find a solution, with socket progamming I can bind any IP I want, but I don't see a way to do this with a mySQL connection.
Anyway, I was able to accomplish this by adding a second NIC on the Server and putting the single IP on 1 NIC and all the other IP's on the second NIC. Then putting in a route that forces the traffic through the Primary NIC interface to MySQL.
Without two NICS, you can't select which IP it uses, But with two you can assign the routes to either NIC (Interface).
I'm in a situation where I have to push data to a remote database, from a Powershell script.
The database's server uses multiple instances, each one using a specific socket.
I'm trying to open a connection remotely, using the .Net MySQL connector as follow :
$mdir = Split-Path $script:MyInvocation.MyCommand.Path
[void][system.reflection.Assembly]::LoadFrom("$mdir\MySQL.Data.dll")
$connection = New-Object MySql.Data.MySqlClient.MySqlConnection
$connection.ConnectionString = "host=$myHost;port=$Port;uid=$User;pwd=$Pass;database=$Database;Socket=$Socket;Pooling=False"
$connection.Open()
I'm getting an error saying that Socket is not an existing keyword.
I've found reference to that keyword on google, but indeed not in the official documentation.
Example showing what I want to connect to :
Server : db.domain.com
Port : 2345
Socket : /var/sockets/mycustomsocket.sock
Is there a way to do what I want, and if so, what am I doing wrong ?
EDIT
What I was doing wrong is putting too much trust into the technical knowledge of my client, but at least, I learned something !
The case I described is pure nonsense due to the way MySQL works.
When an instance uses a socket, that socket is bound to a specific port. The case that my client described to me that lead to that question is therefore impossible.
It is not possible to have several instances of MySQL listening on the same port, but using different sockets. Wanting to connect to a remote file socket is therefore a non issue, and you should be able to connect using ip/hostname and port.
The Socket parameter in MySQL is supposed to be used locally, as it was noted in the comments.
introduction
when configuring elasticsearch I ran into a problem with binding the
listening interfaces.
somehow the documentation does not provide how to setup multiple network interfaces (network def and bind def)
problem description
my intention is to setup the network.bind_host as _eth1:ipv4_ and _local_
even when trying to setup the bind_host as _local_ only,
the elastic search port 9200 is still only reachable by eth1 (of course i have restarted the server)
solutions tried
i have tested the firewall configuration by setting up a netcat server and this one works perfectly for that port
so this results in 2 Questions:
how to configure multiple nics? (whats the notation?)
would i require to change the network.publish_host ?!
.
any other pointers?
current configuration:
network.bind_host: _eth1:ipv4_
network.publish_host: _eth1:ipv4_
network.host: _eth1:ipv4_
also tested configuration:
network.bind_host: _local_
network.publish_host: _eth1:ipv4_
network.host: _local_
PS:
afaik the publish_host is the nic for the inter-server communication
Using a YAML list for the desired property:
network.bind_host:
- _local_
- _en0:ipv4_
If I understand this answer correctly, publish_host should be _eth1:ipv4_. Your publish_host has to be a one of the interfaces to which elasticsearch binds via the bind_host property.
The above linked answer is actually great, so I have to cite it here:
"bind_host" is the host that an Elasticsearch node uses in the socket
bind call when starting the network. Due to socket programming model,
you can "bind" to an address. By referencing an "address", the socket
allows access to one or all underlying network devices. There are
several addresses with predefined semantics, e.g. 0.0.0.0 is reserved
for "bind to all network devices". So the "bind_host" address does not
necessarily reflect a single unique address.
"publish_host" must be a single unique network address. It is used for
connect calls by other nodes, not for socket bind call by the node
itself. By using "publish_host" all nodes and clients can be sure they
can connect to this node. Declaring this single unique address to the
outside can be interpreted as "publishing", so it is called
"publish_host".
You can not set "bind_host" and "publish_host" to arbitrary values,
the values must adhere to the underlying socket model.
I saw the following statement on StackOverflow and was wondering about its meaning:
If you connect via 'localhost', the connection will automatically be established via the MySQL socket, which is really cheap anyways.
The discussion thread was pretty old, so I didn't want to comment on it.
Basically what I understand is, that using 'localhost' when connecting to your mysql database has certain advantages - such as "automatically established connections via MySQL socket". What does that mean exactly?
Currently I'm using
mysql_connect("73.21.24.201", [...]);
(changed to a random IP Address)
Does it make any difference? Can I change it to "localhost" without having to worry about it? (The mysql server is obviously on the same server/ip address as my website/application)
When you connect to 'localhost' you'll connect using a Unix socket, which is just a communications channel for the local processes to use. The big advantage of this is that you can disable networking completely in MySQL, and negate any processing overhead and security risks that go along with that.
When MySQL starts, it creates a socket file (typically at a place like /var/lib/mysql/mysql.sock) that your client program needs to be able to find. On a typical PHP (you didn't say, but I'm assuming) setup, it should know where to find this socket. If not, check /etc/my.cnf and /etc/php.ini to make sure the values match.
And finally, if that is PHP, stop using mysql_*() functions in PHP right now! They have been deprecated for years and are inefficient and insecure.
I'm curious if it is possible to map a UNIX socket on to an INET socket. The situation is simply that I'd like to connect to a MySQL server. Unfortunately it has INET sockets disabled and therefore I can only connect with UNIX sockets. The tools I'm using/writing have to connect on an INET socket, so I'm trying to see if I can map one on to the other.
It took a fair amount of searching but I did find socat, which purportedly does what I'm looking for. I was wondering if anyone has any suggestions on how to accomplish this. The command-line I've been using (with partial success) is:
socat -v UNIX-CONNECT:/var/lib/mysql/mysql.sock TCP-LISTEN:6666,reuseaddr
Now I can make connections and talk to the server. Unfortunately any attempts at making multiple connections fail as I need to use the fork option but this option seems to render the connections nonfunctional.
I know I can tackle the issue with Perl (my preferred language), but I'd rather avoid writing the entire implementation myself. I familiar with the IO::Socket libraries, I am simply hoping anyone has experience doing this sort of thing. Open to suggestions/ideas.
Thanks.
Reverse the order of your arguments to socat, and it works.
socat -v tcp-l:6666,reuseaddr,fork unix:/var/lib/mysql/mysql.sock
This instructs socat to
Listen on TCP port 6666 (with SO_REUSEADDR)
Wait to accept a connection
When a connection is made, fork. In the child, continue the steps below. In the parent, go to 2.
Open a UNIX domain connection to the /var/lib/mysql/mysql.sock socket.
Transfer data between the two endpoints, then exit.
Writing it the other way around
socat -v unix:/var/lib/mysql/mysql.sock tcp-l:6666,reuseaddr,fork
doesn't work, because this instructs socat to
Open a UNIX domain connection to the /var/lib/mysql/mysql.sock socket.
Listen on TCP port 6666 (with SO_REUSEADDR)
Wait to accept a connection
When a connection is made, spawn a worker child to transfer data between the two addresses.
The parent continues to accept connections on the second address, but no longer has the first address available: it was given to the first child. So nothing useful can be done from this point on.
Yes, you can do this in Perl.
Look at perlipc, IO::Select, IO::Socket and Beej's Guide to Network Programming.
You might want to consider doing it in POE - it's asynchronous library for dealing with events, so it looks like great for the task.
It is not 100% relevant, but I use POE to write proxy between stateless protocol (HTTP) and statefull protocol (telnet session, and more specifically - MUD session), and it was rather simple - You can check the code in here: http://www.depesz.com/index.php/2009/04/08/learning-poe-http-2-mud-proxy/.
In the comments somebody also suggested Coro/AnyEvent - I haven't played with it yet, but you might want to check it.