MySQL資料庫的套接字檔案和pid檔案

lhrbest發表於2017-08-24
MySQL資料庫的套接字檔案和pid檔案



socket檔案:當用Unix域套接字方式進行連線時需要的檔案。

pid檔案:MySQL例項的程式ID檔案。

MySQL表結構檔案:用來存放MySQL表結構定義檔案。

套接字檔案

Unix系統下本地連線MySQL可以採用Unix域套接字方式,這種方式需要一個套接字(socket)檔案。套接字檔案可由引數socket控制。一般在/tmp目錄下,名為mysql.sock:

show variables like 'socket'\G


mysql有兩種連線方式,常用的一般是tcp
mysql -h(ip) -uroot -pxxx #常用的
mysql -S /tmp/mysqld.sock

      MySQL 採用unix socket連線方式,比用tcp的方式更快,但只適用於mysql和應用同在一臺PC上。如果不在同一臺pc上,就沒有辦法連線了。



直接就用tcp方式mysql -h localhost -u root -proot直接登入了,沒有用套接字這方式。由此也可看出不是必須。





 socket檔案類似於管道,但它是在網路上面工作的。您到計算機就是靠它來做網路處理的。您可能聽說過“Winsock”,那是 Windows 的套介面。我們在這裡不深入談有關套介面,因為如果您不寫程式,您不會用到它,但如果您看到您系統裡有個檔案型別是s,您知道它是什麼就行了。
  比如說mysql 執行的時候通常會產生一個socket檔案。
  [root@yaoyao tmp]# ls -l /tmp/mysql.sock
  srwxrwxrwx 1 mysql mysql 08月 7 10:03 mysql.sock
  /tmp目錄下還有一些socket檔案,多半是執行Xwindows的時候產生的。


linux、unix這種系統認為io、裝置等等都是檔案,socket也是io

https://en.wikipedia.org/wiki/Unix_domain_socket


Unix domain socket or IPC socket (inter-process communication socket) is a data communications endpoint for exchanging data between processes executing on the same host operating system. Like named pipes, Unix domain sockets support transmission of a reliable stream of bytes (SOCK_STREAM, compare to TCP). In addition, they support ordered and reliable transmission of datagrams (SOCK_SEQPACKET, compare to SCTP), or unordered and unreliable transmission of datagrams (SOCK_DGRAM, compare to UDP). The Unix domain socket facility is a standard component of POSIX operating systems.

The API for Unix domain sockets is similar to that of an Internet socket, but rather than using an underlying network protocol, all communication occurs entirely within the operating system kernel. Unix domain sockets use the file system as their address name space. Processes reference Unix domain sockets as file system inodes, so two processes can communicate by opening the same socket.

In addition to sending data, processes may send file descriptors across a Unix domain socket connection using the sendmsg() and recvmsg() system calls. This allows the sending processes to grant the receiving process access to a file descriptor for which the receiving process otherwise does not have access.[1] This can be used to implement a rudimentary form of capability-based security.[2] For example, this allows the Clam AntiVirus scanner to run as an unprivilegeddaemon on Linux and BSD, yet still read any file sent to the daemon's Unix domain socket.




pid檔案

當MySQL例項啟動時,會將自己的程式ID寫入一個檔案中——該檔案即為pid檔案。該檔案可由引數pid_file控制。預設路徑位於資料庫目錄下,檔名為主機名.pid。

show variables like 'pid_file'\G

MySQL表結構檔案

因為MySQL外掛式儲存引擎的體系結構的關係,MySQL對於資料的儲存是按照表的,所以每個表都會有與之對應的檔案(對比SQL Server是按照每個資料庫下的所有表或索引都存在mdf檔案中)。不論採用何種儲存引擎,MySQL都有一個以frm為字尾名的檔案,這個檔案記錄了該表的表結構定義。二進位制檔案。

frm還用來存放檢視的定義,如我們建立了一個v_a檢視,那麼對應地會產生一個v_a.frm檔案,用來記錄檢視的定義,該檔案是文字檔案,可以直接使用cat命令進行檢視:

show variables like 'datadir';

exit

cd /usr/local/var/mysql/test

cat v_a.frm

TYPE=VIEW query=select 'test'.'a'.'b'AS'b'from'test'.'a' md5=4eda70387716a4d6c96f3042dd68b742
updatable=1 algorithm=0 definer_user=root
definer_host=localhost
suid=2 with_check_option=0 timestamp=2010-08-04 072336 create-version=1 source=select*from a
client_cs_name=utf8
connection_cl_name=utf8_general_ci
view_body_utf8=select'test'.'a'.'b'AS'b'from'test'.'a'








About Me

.............................................................................................................................................

● 本文整理自網路

● 本文在itpub(http://blog.itpub.net/26736162/abstract/1/)、部落格園(http://www.cnblogs.com/lhrbest)和個人微信公眾號(xiaomaimiaolhr)上有同步更新

● 本文itpub地址:http://blog.itpub.net/26736162/abstract/1/

● 本文部落格園地址:http://www.cnblogs.com/lhrbest

● 本文pdf版、個人簡介及小麥苗雲盤地址:http://blog.itpub.net/26736162/viewspace-1624453/

● 資料庫筆試面試題庫及解答:http://blog.itpub.net/26736162/viewspace-2134706/

● DBA寶典今日頭條號地址:http://www.toutiao.com/c/user/6401772890/#mid=1564638659405826

.............................................................................................................................................

● QQ群號:230161599(滿)、618766405

● 微信群:可加我微信,我拉大家進群,非誠勿擾

● 聯絡我請加QQ好友646634621,註明新增緣由

● 於 2017-08-01 09:00 ~ 2017-08-31 22:00 在魔都完成

● 文章內容來源於小麥苗的學習筆記,部分整理自網路,若有侵權或不當之處還請諒解

● 版權所有,歡迎分享本文,轉載請保留出處

.............................................................................................................................................

小麥苗的微店https://weidian.com/s/793741433?wfr=c&ifr=shopdetail

小麥苗出版的資料庫類叢書http://blog.itpub.net/26736162/viewspace-2142121/

.............................................................................................................................................

使用微信客戶端掃描下面的二維碼來關注小麥苗的微信公眾號(xiaomaimiaolhr)及QQ群(DBA寶典),學習最實用的資料庫技術。

   小麥苗的微信公眾號      小麥苗的DBA寶典QQ群1     小麥苗的DBA寶典QQ群2        小麥苗的微店

.............................................................................................................................................

MySQL資料庫的套接字檔案和pid檔案
DBA筆試面試講解群1
DBA筆試面試講解群2
歡迎與我聯絡



來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2144037/,如需轉載,請註明出處,否則將追究法律責任。

相關文章