What's the use of socket declaration in config/database.yml ?
Example code:
staging:
adapter: mysql
encoding: utf8
database: (database)
pool: 5
username: (user)
password: (pass)
socket: /tmp/mysql.sock # <--------- this line
My app works, wether this line is commented or not. So what is it for ? What reasons can I have to leave it, comment it or change it's value ?
When two programs want to talk to each other over the network, one program might open up a TCP connection (a "socket") with the other one. The first program needs to know the IP address of the second computer and the port on which the program is listening.
On Linux, when two programs on the same computer want to talk to each other, they can still open up a TCP connection. But they can also open up a connection via a "socket file". Linux makes the socket file API rather similar to the TCP API, so it's not a big deal to update a program that already communicates over the network via TCP to support communicating via socket files too. Socket files are faster than TCP, but only work when both programs are on the same computer.
MySQL has two methods of communicating with it on unix-ish systems, tcp/ip and domain sockets. By specifying the socket Rails, or rather the database driver, will use the socket instead of a network connection. It can be quicker to use the socket but YMMV.
http://dev.mysql.com/doc/refman/5.5/en/connecting.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With