<br />
<br style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;" />
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<hr style="margin:0px;padding:0px;line-height:26px;" />
<div style="line-height:26px;">
<div>
<div>
<span style="font-size:10px;">链接:</span><a href="http://blog.itpub.net/28602568/viewspace-1797619/" style="text-decoration:none;color:#565656;"><span style="font-size:10px;">http://blog.itpub.net/28602568/viewspace-1797619/</span></a>
</div>
<p style="margin-top:0px;margin-bottom:0px;border:0px;vertical-align:baseline;line-height:24px;">
<span style="font-size:10px;">标题:</span><a href="http://blog.itpub.net/28602568/viewspace-1797619/" style="line-height:12px;text-decoration:none;color:#9C2423;font-family:微软雅黑, 黑体, Verdana;"><span style="font-size:10px;">mysql.sock的作用</span></a>
</p>
<div>
<span style="font-size:10px;">作者:</span><a href="http://blog.itpub.net/28602568/" style="text-decoration:none;color:#565656;"><span style="font-size:10px;">lōττéry</span></a><span style="font-size:10px;">©版权所有[文章允许转载,但必须以链接方式注明源地址,否则追究法律责任.]</span>
</div>
</div>
<div>
<hr style="margin:0px;padding:0px;" />
</div>
</div>
<br />
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<span style="font-size:10px;">注释:</span>
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<span style="font-size:10px;"> 前段时间出现过一种情况,localhost本地登录mysql数据库提示不能连接mysql.sock,第三方工具sqlyog可以登录,具体原因如下。</span>
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<br />
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<span style="font-size:10px;">原创内容如下 </span><a href="http://blog.gobbin.cn/archives/mysql-sock" style="text-decoration:none;color:#BD5532;box-sizing:border-box;border:0px;font-family:'Open Sans', Helvetica, Arial, sans-serif;font-style:italic;margin:0px;outline:0px;padding:0px;vertical-align:baseline;-webkit-transition:all 0.2s ease-in-out;transition:all 0.2s ease-in-out;line-height:24px;"><span style="font-size:10px;">mysql.sock的作用</span></a>
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<hr style="margin:0px;padding:0px;" />
<span style="font-family:'Open Sans', Helvetica, Arial, sans-serif;line-height:24px;font-size:10px;">mysql有两种连接方式:</span>
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<span style="font-family:inherit;font-style:inherit;line-height:1.714285714;font-size:10px;">1、TCP/IP</span>
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<span style="font-family:inherit;font-style:inherit;line-height:1.714285714;font-size:10px;">2、socket</span>
<div>
<span style="font-size:10px;">mysql.sock的作用是server和client在同一台服务器,并且使用localhost进行链接的时候,就会使用socket来进行连接——仅此而已</span>
</div>
<div>
<span style="font-size:10px;">也就是:为主机名为localhost建立的MySQL连接,该连接过程通过一个套接字文件mysql.socket实现的。所以该文件被删后,用localhost用户是连接不到MySQL服务器的。</span>
</div>
<div>
<span style="font-size:10px;">必须建立一条tcp/ip连接,即使用127.0.0.1而不是localhost作为-h的参数去连接MySQL服务器,如:mysqladmin -h 127.0.0.1 -u root -p shutdown,强制地建立一条tcp/ip连接;</span>
</div>
<div>
<span style="font-size:10px;">关闭MySQL服务器,再重新以localhost为主机名启动MySQL服务器,它就会重新创建一个套接字文件。</span>
</div>
<div>
<hr style="margin:0px;padding:0px;" />
</div>
<div>
<br />
</div>
<div>
<b><span style="font-size:10px;">对上文加以测试深入了解;</span></b>
</div>
<div>
<span style="color:#FF0000;font-size:10px;">查看mysql.sock具体路径:</span>
</div>
<div>
<span style="font-size:10px;">[root@Wonhigh-Test16 ~]# ps -ef | grep mysql.sock|grep -v "grep"</span><br />
<span style="font-size:10px;">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 </span><b><span style="font-size:10px;">--socket=/var/lib/mysql/mysql.sock</span></b><span style="font-size:10px;"> --port=3306</span><br />
<span style="font-size:10px;">[root@Wonhigh-Test16 ~]# </span>
</div>
<div>
<span style="color:#FF0000;font-size:10px;">转移套接字文件 mysql.sock</span><br />
<span style="font-size:10px;">[root@Wonhigh-Test16 ~]# mv /var/lib/mysql/mysql.sock /var/lib/mysql/mysql1.sock </span>
</div>
<div>
<span style="color:#FF0000;"><span style="font-size:10px;">确认本地登录情况</span><br />
</span><span style="font-size:10px;">[root@Wonhigh-Test16 ~]# mysql -uroot -p123456</span><br />
<span style="font-size:10px;">Warning: Using a password on the command line interface can be insecure.</span><br />
<b><span style="font-size:10px;">ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)</span></b><br />
<span style="font-size:10px;">[root@Wonhigh-Test16 ~]#</span>
</div>
<div>
<span style="color:#FF0000;font-size:10px;">尝试127.0.0.1 tcp/ip连接(第三方工具远程连接都可以‘连接属性会显示为TCP/IP ’)</span>
</div>
<div>
<span style="font-size:10px;">[root@Wonhigh-Test16 ~]# mysql -uroot -p123456 -h127.0.0.1</span>
</div>
<span style="font-size:10px;">Warning: Using a password on the command line interface can be insecure.</span><br />
<span style="font-size:10px;">Welcome to the MySQL monitor. Commands end with ; or \g.</span><br />
<span style="font-size:10px;">Your MySQL connection id is 127</span><br />
<span style="font-size:10px;">Server version: 5.6.19-log</span><br />
<span style="font-size:10px;">Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.</span><br />
<span style="font-size:10px;">Oracle is a registered trademark of Oracle Corporation and/or its</span><br />
<span style="font-size:10px;">affiliates. Other names may be trademarks of their respective owners.</span><br />
<span style="font-size:10px;">Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.</span><br />
<div>
<span style="font-size:10px;">mysql></span>
</div>
<div>
<br />
</div>
<div>
<span style="color:#FF0000;font-size:10px;">恢复本地连接</span>
</div>
<div>
<span style="font-size:10px;">[root@Wonhigh-Test16 ~]# mv /var/lib/mysql/mysql1.sock /var/lib/mysql/mysql.sock</span><br />
</div>
<div>
<span style="font-size:10px;">[root@Wonhigh-Test16 ~]# mysql -uroot -p123456</span><br />
<span style="font-size:10px;">Warning: Using a password on the command line interface can be insecure.</span><br />
<span style="font-size:10px;">Welcome to the MySQL monitor. Commands end with ; or \g.</span><br />
<span style="font-size:10px;">Your MySQL connection id is 121</span><br />
<span style="font-size:10px;">Server version: 5.6.19-log MySQL Community Server (GPL)</span><br />
<span style="font-size:10px;">Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.</span><br />
<span style="font-size:10px;">Oracle is a registered trademark of Oracle Corporation and/or its</span><br />
<span style="font-size:10px;">affiliates. Other names may be trademarks of their respective owners.</span><br />
<span style="font-size:10px;">Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.</span>
</div>
<div>
<br />
<span style="font-size:10px;">mysql> exit</span><br />
<span style="font-size:10px;">Bye</span><br />
<span style="font-size:10px;">[root@Wonhigh-Test16 ~]# </span>
</div>
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<br />
</div>
<div style="color:#666666;font-family:微软雅黑;line-height:normal;orphans:2;text-align:-webkit-auto;white-space:normal;widows:2;font-size:medium;background-color:#FFFFFF;">
<div style="height:auto;overflow:hidden;">
<div style="line-height:26px;">
<span style="font-size:10px;"> 【源于本人笔记】 若有书写错误,表达错误,请指正... </span>
</div>
<div style="line-height:26px;">
<div style="line-height:normal;">
<br />
<hr style="margin:0px;padding:0px;" />
<div>
<span style="color:#464646;"><span style="line-height:18px;"><span style="font-size:10px;">此条目发表在</span><a href="http://blog.itpub.net/28602568/cid-175422-abstract-1/" style="text-decoration:none;color:#565656;"><span style="font-size:10px;"> </span></a><a href="http://blog.itpub.net/28602568/cid-175422-abstract-1/" style="text-decoration:none;color:#565656;"><span style="font-size:10px;">MySQL</span></a><span style="font-size:10px;"> </span></span><span style="line-height:18px;"><span style="font-size:10px;">分类目录。将</span><a href="http://blog.itpub.net/28602568/viewspace-1797619/" style="text-decoration:none;color:#565656;"><span style="font-size:10px;">固定连接</span></a></span><span style="line-height:18px;font-size:10px;">加入收藏夹。</span></span>
</div>
<hr style="margin:0px;padding:0px;" />
</div>
</div>
</div>
</div>
<br />
<span style="font-size:10px;"></span>
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26909803/viewspace-1878034/
,如需转载,请注明出处,否则将追究法律责任。