注释:
在此期间,如果localhost本地登录到mysql数据库,系统会通知您无法连接到mysql.sock,并且第三方工具sqlyog现在可以登录。 具体理由如下。
mysql.sock角色
mysql有两种连接方法。
1、TCP/IP
2、插座
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 @ won high-test 16~] # PS-ef|grep MySQL.sock|grep-v ' grep '
mysql 31108 30650 0 Sep10? 0:0:17/usr/sbin/mysqld-- basedir=/usr-- datadir=/var/lib/MySQL-- plugin-dir=/usr/lib 64 mysqld
[root@Wonhigh-Test16 ~]#
传输套接字文件mysql.sock
[ root @ won high-test 16~~ ] # mv/var/lib/MySQL/MySQL.sock/var/lib/MySQL/MySQL1. sock
检查本地登录状态
[ root @ won high-test 16~~ ] # MySQL-uroot-p 123456
warning : usingapasswordonthecommandlineinterfacecanbeinsecure。
error2002(hy000 ) : can ' tconnecttolocalmysqlserverthroughsocket '/var/lib/MySQL/MySQL.sock ' (2) )。
[root@Wonhigh-Test16 ~]#
127.0.0.1尝试TCP/IP连接(所有第三方工具的远程连接都显示为“连接属性为TCP/IP”)
[ root @ won high-test 16~] # MySQL-uroot-p 123456-h 127.0.0.1
warning : usingapasswordonthecommandlineinterfacecanbeinsecure。
welcometothemysqlmonitor.command send with; 或 g。
Your MySQL connection id is 127
服务器版本:5.6. 19-log
版权所有(c ) 2000,2014,Oracle and/oritsaffiliates.all rights reserved。
oracleisaregisteredtrademarkoforaclecorporationand/or its
affiliates.othernamesmaybetrademarksoftheirrespectiveowners。
类型帮助;' or 'h ' forhelp.type 'coclearthecurrentinputstatement。
mysql
恢复本地连接
[ root @ won high-test 16~~ ] # mv/var/lib/MySQL/MySQL1. sock/var/lib/MySQL/MySQL.sock
[ root @ won high-test 16~~ ] # MySQL-uroot-p 123456
warning : usingapasswordonthecommandlineinterfacecanbeinsecure。
welcometothemysqlmonitor.command send with; 或 g。
Your MySQL connection id is 121
服务器版本:5.6.19-logmysqlcommunityserver (GPL ) )。
版权所有(c ) 2000,2014,Oracle and/oritsaffiliates.all rights reserved。
oracleisaregisteredtrademarkoforaclecorporationand/or its
affiliates.othernamesmaybetrademarksoftheirrespectiveowners。
类型帮助;' or 'h ' forhelp.type 'coclearthecurrentinputstatement。
mysql exit
Bye
[root@Wonhigh-Test16 ~]#