mysql.sock的作用


标题:mysql.sock的作用

作者:lōττéry©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]

注释:
  前段时间出现过一种情况,localhost本地登录mysql数据库提示不能连接mysql.sock,第三方工具sqlyog可以登录,具体原因如下。
 
原创内容如下  mysql.sock的作用

mysql有两种连接方式:
1、TCP/IP
2、socket

mysql.sock的作用是server和client在同一台服务器,并且使用localhost进行链接的时候,就会使用socket来进行连接——仅此而已
也就是:为主机名为localhost建立的MySQL连接,该连接过程通过一个套接字文件mysql.socket实现的。所以该文件被删后,用localhost用户是连接不到MySQL服务器的。
必须建立一条tcp/ip连接,即使用127.0.0.1而不是localhost作为-h的参数去连接MySQL服务器,如:mysqladmin -h 127.0.0.1 -u root -p shutdown,强制地建立一条tcp/ip连接;
关闭MySQL服务器,再重新以localhost为主机名启动MySQL服务器,它就会重新创建一个套接字文件。

 
对上文加以测试深入了解;
查看mysql.sock具体路径:
[root@Wonhigh-Test16 ~]# ps -ef | grep mysql.sock|grep -v "grep"
mysql    31108 30650  0 Sep10 ?        00:03:17 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --user=mysql --log-error=/var/lib/mysql/Wonhigh-Test16.err --pid-file=/var/lib/mysql/Wonhigh-Test16.pid --socket=/var/lib/mysql/mysql.sock --port=3306
[root@Wonhigh-Test16 ~]# 
转移套接字文件 mysql.sock
[root@Wonhigh-Test16 ~]# mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql1.sock 
确认本地登录情况
[root@Wonhigh-Test16 ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
[root@Wonhigh-Test16 ~]#
尝试127.0.0.1 tcp/ip连接(第三方工具远程连接都可以‘连接属性会显示为TCP/IP ’)
[root@Wonhigh-Test16 ~]# mysql -uroot -p123456 -h127.0.0.1

Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 127
Server version: 5.6.19-log
Copyright (c) 2000, 2014, 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>
 
恢复本地连接
[root@Wonhigh-Test16 ~]# mv /var/lib/mysql/mysql1.sock /var/lib/mysql/mysql.sock
[root@Wonhigh-Test16 ~]# mysql -uroot -p123456
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 121
Server version: 5.6.19-log MySQL Community Server (GPL)
Copyright (c) 2000, 2014, 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> exit
Bye
[root@Wonhigh-Test16 ~]# 

[转帖]mysql.sock的作用的更多相关文章

  1. mysql.sock的作用

    1.在编译安装mysql的时候,会将mysql的配置文件复制到/etc/my.conf中: [root@Web-lnmp02 mysql]# cp support-files/my-small.cnf ...

  2. mysql 中的socket 即 mysql.sock的作用

    这个mysql.sock应该是mysql的主机和客户机在同一host上的时候,使用unix domain socket做为通讯协议的载体,它比tcp快.通常遇到这个问题的原因就是你的mysql ser ...

  3. MySQL的mysql.sock文件作用(转)

    mysql.sock是可用于本地服务器的套接字文件.它只是另一种连接机制. 不包含任何数据,但仅用于从客户端到本地服务器来进行交换数据.

  4. Mac mySql ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)的解决办法

    我的环境:Mac 10.11.6 ,mysql  5.7.14  . mac mySql 报错ERROR 2002 (HY000): Can't connect to local MySQL serv ...

  5. Mysql启动找不到mysql.sock文件问题(Centos7)

    刚装完Mysql5.7,将Mysql添加到开机自启.reboot之后mysql服务却没启动起来, 直接输入mysql –uroot –p ,出现如下错误,找不到mysql.sock文件.用servic ...

  6. 亲测有效,解决Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) ";

    版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/hjf161105/article/details/78850658 最近租了一个阿里云云翼服务器,趁 ...

  7. mysql.sock文件的作用

    mysql.sock应该mysql的主机和客户机在同一host上的时候,使用unix domain socket做为通讯协议的载体,它比tcp快.Mysql有两种连接方式: (1)TCP/IP  (2 ...

  8. 【转】mysql.sock文件的作用

    Mysql有两种连接方式: (1),TCP/IP (2),socket 对mysql.sock来说,其作用是程序与mysqlserver处于同一台机器,发起本地连接时可用. (如果程序跟mysql在同 ...

  9. MAC中Django中runserver提示Can't connect to local MySQL server through socket '/tmp/mysql.sock错误

    好像不止遇到一次,直接Google就可以了,在stackoverflow中就有答案,答案就是你没有开MySQL - -. stackoverflow链接见 http://stackoverflow.c ...

随机推荐

  1. 第二篇:请求库之requests,selenium

    requests模块 一.介绍 #介绍:使用requests可以模拟浏览器的请求,比起之前用到的urllib,requests模块的api更加便捷(本质就是封装了urllib3) #注意:reques ...

  2. Scala传递参数遇到的坑

    1.方法中的参数全为val型. 例: def insertMap(map:=>Map[String,Int]):Unit={ map+=("b"->2)    //报错 ...

  3. linux-shell脚本基础-2

    1,用户组 添加用户 useradd -u UID -o -g 指定 GID或组名 -c 注释信息 -d 家目录 -s shell -G 附加组 -r 系统用户 -m 家目录,系统用户 -M 不创建家 ...

  4. 【BZOJ1098】办公楼biu(补图,bfs,链表)

    题意:有n个点m条边,要求将点尽可能多的分成若干个部分,使得若两个点不在同一个部分则他们之间必定有边 n<=1e5,m<=2e6 思路:From https://blog.csdn.net ...

  5. nginx 日志文件分隔

    Nginx命令 Nginx命令帮助如下 nginx -h nginx version: nginx/0.8.45 Usage: nginx [-?hvVt] [-s signal] [-c filen ...

  6. sqli-labs(26a)

    0x01偷偷看一波源码 和26关一样 闭合变成了’)而已 0X01构造语句爆库名 这是百度到的 第一个 ' 首先闭合id='$id' 中的',%a0是空格的意思,(ps:此处我的环境是ubuntu14 ...

  7. maven 配置私服 连接

    两种方法: 1.在单个项目的pom.xml中使用 私服的连接地址,这样只对该项目起作用. 2.在maven的setting.xml配置中添加私服的连接地址.这样对所有项目起作用. 本文章只演示第二种方 ...

  8. 【每日一包0002】array-first

    github地址:https://github.com/ABCDdouyae... array-first 获取数组的第一项或者前几项 文档地址:https://www.npmjs.com/packa ...

  9. maven 报错 Cannot resolve plugin org.apache.maven.plugins:maven-war-plugin:2.1.1

    主要原因是本地maven的配置文件和仓库地址不一致.

  10. 高级软件测试技术-任务进度-Day02

    任务进度11-14 使用工具 Jira 小组成员 华同学.郭同学.穆同学.沈同学.覃同学.刘同学 任务进度 在经过了昨天的基本任务分配之后,今天大家就开始了各自的内容,以下是大家任务的进度情况汇总. ...