zoukankan      html  css  js  c++  java
  • MySQL数据库的套接字文件和pid文件

    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        小麦苗的微店

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

    img_e3029f287d989cd04bd75432ecc1c172.png
    DBA笔试面试讲解群1
    DBA笔试面试讲解群2
    欢迎与我联系



  • 相关阅读:
    ATM演示
    Java类集框架之LinkedList源码剖析
    字节流
    查询信息的服务器 客户端设立 支持并发多线程
    Java I/O
    java 一道多线程的题
    java面向对象
    入门IT
    解决loadrunner录制时 Request Connection: Remote Server @ 0.0.0.0:80 (Service=?) NOT PROXIED! (REASON: Unable to connect to remote server: rc = -1 , le = 0)问题
    可用于测试的接口(网上搜集自行甄别)
  • 原文地址:https://www.cnblogs.com/twodog/p/12139551.html
Copyright © 2011-2022 走看看