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. windows上部署hadoop(单机版)

    在window系统开发程序时,远程linux服务器上的hadoop速度很慢,影响开发效率,能不能在本地搭建hadoop环境的?答案肯定的,且看下文如何在window上部署hadoop: (源文地址:h ...

  2. 运维工程师之IDC系列

    因为我公司在用浪潮服务器,所以说链接暂时是浪潮服务器 1.用UltraISO制作U盘启动安装系统  链接 http://www.4008600011.com/archives/8816 ones 刻录 ...

  3. docker-compose命令及yaml文件

    Docker-compose常用命令 docker-compose up -d nginx 构建建启动nignx容器 docker-compose exec nginx bash 登录到nginx容器 ...

  4. #419 Div2 Problem B Karen and Coffee (统计区间重叠部分 && 前缀和)

    题目链接 :http://codeforces.com/contest/816/problem/B 题意 :给出 n 表示区间个数,限定值 k 以及问询次数 q,当一个数被大于或等于 k 个区间重复覆 ...

  5. 线程工具类ThreadUtils

    package yqw.java.util; public class ThreadUtils { /**     * showThreadInfo     *      * @return     ...

  6. 洛谷P3948 数据结构——题解

    题目传送 感觉这道题秀了我一地的智商... 审题没审好,没确定带修改的操作中询问的次数<=1000,且max和min都是事先给好.不变的.想了半天线段树.分块,却忘了最基础的暴力. 写不出题时先 ...

  7. AttributeError: module 'datetime' has no attribute 'now'

    在用时间转化时,一直报AttributeError: module 'datetime' has no attribute 'now', 我用的 import datetime   datetime ...

  8. es索引基本操作(2)之 索引映射(mappings)管理和索引库配置管理(settings)

    1:索引的映射管理 elasticsearch中的文档等价于java中的对象 , 那么在java对象中有字段(比如string.int.long等): 同理在elasticsearch索引中的具体字段 ...

  9. sqli-labs(28a)

    0X01构造闭合 爆字段数 /?id=') order by 1%23 ?id=') order by 5%23 偷看一下源码 就只过滤了union select 闭合') 那我们来尝试一下 0X02 ...

  10. 深入浅出mysql笔记---0、序

    深入浅出mysql笔记---0.序 一.总结 一句话总结: 心得:买书之前建议先找找电子书,纸质书太难带了 1.开源作用? 开源对mysql的发展至关重要 2.mysql在2002年就全面支持了事务, ...