1.pid-file介绍

MySQL 中的 pid 文件记录的是当前 mysqld 进程的 pid ,pid 亦即 Process ID 。可以通过 pid-file 参数来配置 pid 文件路径及文件名,如果未指定此变量,则 pid 文件默认名为 host_name.pid ,存放的路径默认放在 MySQL 的数据目录。

建议指定 pid 文件名及路径,pid 目录权限要对 mysql 系统用户放开,具体配置可参考如下:

#my.cnf配置文件[mysqld]pid-file=/data/mysql/tmp/mysqld.pid#查看mysqld进程[root@localhost~]#ps-ef|grepmysqldroot867010Jun09?00:00:00/bin/sh/usr/local/mysql/bin/mysqld_safe--datadir=/data/mysql/data--pid-file=/data/mysql/tmp/mysqld.pidmysql935386700Jun09?00:01:23/usr/local/mysql/bin/mysqld--basedir=/usr/local/mysql--datadir=/data/mysql/data--plugin-dir=/usr/local/mysql/lib/plugin--user=mysql--log-error=/data/mysql/logs/error.log--pid-file=/data/mysql/tmp/mysqld.pid--socket=/data/mysql/tmp/mysql.sock#查看pid文件内容[root@localhost~]#cat/data/mysql/tmp/mysqld.pid9353

有时候可能会遇到因 pid 文件问题而启动失败的情况,这几类报错你可能遇到过:

Can‘t start server: can‘t create PID file: No such file or directory

ERROR! MySQL server PID file could not be found

ERROR! The server quit without updating PID file

上面几类 pid 相关报错解决方法其实都是类似的,首先要看下 error log 找到具体报错,然后查看配置文件,确保 pid 文件目录路径正确且有权限有空间,之后可以看下 mysqld 进程是否存在,若存在可手动 kill 掉,若有残留的 pid 文件也可以先删掉,一切排查就绪后,再次重新启动,一般即可成功。

2.socket文件介绍

socket 即 Unix 套接字文件,在类 unix 平台,客户端连接 MySQL 服务端的方式有两种,分别是 TCP/IP 方式与 socket 套接字文件方式。Unix 套接字文件连接的速度比 TCP/IP 快,但是只能连接到同一台计算机上的服务器使用。

通过设置 socket 变量可配置套接字文件路径及名称,默认值为 /tmp/mysql.sock (对于某些发行格式,目录可能有所不同)。参考配置如下:

#my.cnf配置文件[mysqld]socket=/data/mysql/tmp/mysql.sock[client]socket=/data/mysql/tmp/mysql.sock#查看对应目录下的socket文件root@localhosttmp]#ls-lhtotal8.0Ksrwxrwxrwx1mysqlmysql0Jun1015:19mysql.sock-rw-------1mysqlmysql6Jun1015:19mysql.sock.lock#通过-S命令指定socket登录[root@localhost~]#mysql-uroot-pxxxx-S/data/mysql/tmp/mysql.sockmysql:[Warning]Usingapasswordonthecommandlineinterfacecanbeinsecure.WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis12Serverversion:8.0.22MySQLCommunityServer-GPLCopyright(c)2000,2020,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleCorporationand/oritsaffiliates.Othernamesmaybetrademarksoftheirrespectiveowners.Type'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.mysql>status--------------mysqlVer8.0.22forLinuxonx86_64(MySQLCommunityServer-GPL)Connectionid:12Currentdatabase:Currentuser:root@localhostSSL:NotinuseCurrentpager:stdoutUsingoutfile:''Usingdelimiter:;Serverversion:8.0.22MySQLCommunityServer-GPLProtocolversion:10Connection:LocalhostviaUNIXsocketServercharacterset:utf8mb4Dbcharacterset:utf8mb4Clientcharacterset:utf8mb4Conn.characterset:utf8mb4UNIXsocket:/data/mysql/tmp/mysql.sockBinarydataas:HexadecimalUptime:1hour27min31secThreads:3Questions:27Slowqueries:0Opens:135Flushtables:3Opentables:56Queriespersecondavg:0.005

总结:

本篇文章介绍了 MySQL 中的 pid 及 socket 文件的具体配置及作用。其实这两个参数还是比较好维护的,一开始配置好不要去动它就好了,若遇到重启报错的情况,根据错误日志慢慢来排查,细心的操作,总会找到问题的。

更多相关文章

  1. MySQL系列多表连接查询92及99语法示例详解教程
  2. Linux下MYSQL 5.7 找回root密码的问题(亲测可用)
  3. MySQL 什么时候使用INNER JOIN 或 LEFT JOIN
  4. Android(安卓)- Manifest 文件 详解
  5. Android的Handler机制详解3_Looper.looper()不会卡死主线程
  6. Selector、shape详解(一)
  7. android2.2资源文件详解4--menu文件夹下的菜单定义
  8. android从服务器下载文件(php+apache+win7+MySql)
  9. Android发送短信方法实例详解

随机推荐

  1. Android ListView简单实用
  2. android send key event
  3. android 学习链接大集合
  4. Android ListView(Selector 颜色)
  5. linux下获取环境变量(Android)
  6. Android(安卓)获取最新图片
  7. Google code android开源项目(一)
  8. android源码链接
  9. Android 使用AsyncHttpClient文件上传与
  10. 第一行代码Android第三课