餐厅服务员岗位职责mysql中pid-file_MySQL中socket和pid-file的作⽤
1.MySQL 连接⽅式
(1):TCP/IP 套接字⽅式
这种⽅式会在TCP/IP 连接上建⽴⼀个基于⽹络的连接请求,⼀般是client连接跑在Server上的MySQL实例,2台机器通过⼀个TCP/IP ⽹络连接。
C:\Users\gechong>mysql -h 192.168.1.10 -uroot -p虹猫蓝兔七侠传主题曲
Enter password: *
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.5.20-log MySQL Community Server (GPL)
Copyright (c) 2000, 2011, 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.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
这⾥的客户端是Windows,向IP为192.168.1.10 的服务器上的MySQL实例发起了TCP/IP请求,连接成功后就可以使⽤MySQL了。
(2):UNIX域套接字
UNIX域套接字并不是⽹络协议,所以只能在MySQL客户端和数据库实例在⼀台服务器上使⽤,⽤户可以在配置⽂件中指定套接字⽂件,在登录mysql的时候可以加上socket。使⽤socket你⽆须定义连接host的具体IP地址,只要为空或127.0.0.1就可以。
–socket=/tmp/mysql.sock
mysql> SHOW VARIABLES LIKE ‘socket’;郑秀妍
+—————+—————–+
| Variable_name | Value |
+—————+—————–+
| socket | /tmp/mysql.sock |倪齐民老婆
+—————+—————–+
1 row in set (0.00 sec)
#mysql -uroot -S/tmp/mysql.sock
陈德容个人资料2.MySQL pid⽂件
MySQL pid ⽂件记录的是当前 mysqld 进程的 pid,pid 亦即 Process ID。
未指定 pid ⽂件时,pid ⽂件默认名为 主机名.pid,存放的路径在默认 MySQL 的数据⽬录。
通过mysqld_safe启动MySQL时,mysqld_safe会检查pid⽂件,如果pid⽂件不存在,不做处理;如果⽂件存在,且pid已占⽤则报错;如果⽂件存在且pid未占⽤,则删除pid⽂件。
mysqld 启动后会通过 create_pid_file 函数新建 pid ⽂件,通过getpid() 获取当前进程 pid 并将 pid 写⼊ pid ⽂件。乘风破浪会有时直挂云帆济沧海的意思
因此,通过 mysqld_safe 启动时, MySQL pid ⽂件的作⽤是:防⽌同⼀个数据库被启动多次。