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 ~]# 

最新文章

  1. Linux常用的命令以及一些常见的问题
  2. cf#382div2
  3. Java面试常见各种概念区别比较
  4. C语言学习010:fopen读写文件
  5. Introduction to Monte Carlo Tree Search (蒙特卡罗搜索树简介)
  6. Android 三种方式实现自定义圆形页面加载中效果的进度条
  7. Lambda Action Func练习
  8. javascript——base64
  9. web client
  10. Oracle 安装时候的网络相关内核参数
  11. 理解对象模型图(Reading OMDS)
  12. 搭建git远程服务器三步骤
  13. MyBatis_关联关系查询
  14. 【Flask】 项目结构说明
  15. MSP430F149串口收发程序的学习(一)
  16. 对于Java Bean的类型转换问题()使用 org.apache.commons.beanutils.ConvertUtils)
  17. Jquery实现checkbox按shift多选
  18. C# 枚举 Flag属性(权限设计)
  19. Android切换横竖屏不销毁前台Activity,也不影响后台Activity
  20. 第21月第6天 zhihu如何用3个月零基础入门机器学习

热门文章

  1. apk反编译(仅供娱乐)
  2. JAVA笔记23-IO流(1)
  3. 算法——求n对()有多少种输出方式?
  4. asp.net mvc 异步控制器
  5. hdu 1754 线段树 水题 单点更新 区间查询
  6. Linux vi/vim and linux yum 命令
  7. Spring Boot教程(一)在springboot中用redis实现消息队列
  8. bootstrap基础讲解
  9. Ubuntu18.04修改为阿里云
  10. spring boot + mybatis + layui + shiro后台权限管理系统