What is the socket declaration for, in Ruby on Rails database.yml?

后端 未结 4 897
耶瑟儿~
耶瑟儿~ 2020-12-31 09:38

What\'s the use of socket declaration in config/database.yml ?

Example code:

staging:
  adapter: mysql
  encoding: utf8
  database: (database)
  pool         


        
相关标签:
4条回答
  • 2020-12-31 10:09

    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

    0 讨论(0)
  • 2020-12-31 10:11

    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.

    0 讨论(0)
  • 2020-12-31 10:14

    I wasted a whole afternoon because of a socket specified in my database.yml - the database specifications for the test environment simply weren't parsed. So if you have a problem with your test-database not being accessible although everything seems to be fine with it, try removing the socket specification.

    0 讨论(0)
  • 2020-12-31 10:17

    This displays the file location for the UNIX socket:

    mysqladmin version -u 'your user name' -p
    

    result:

    mysqladmin  Ver 8.42 Distrib 5.7.26, for Linux on x86_64
    Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Server version      5.7.26-0ubuntu0.19.04.1
    Protocol version    10
    Connection      Localhost via UNIX socket
    UNIX socket     /var/run/mysqld/mysqld.sock
    Uptime:         6 min 40 sec
    

    Your user must have granted permissions.

    0 讨论(0)
提交回复
热议问题