mysql.sock.lock的作用,[轉帖]mysql.sock的作用

本文详细讲述了mysql.sock的作用,当其丢失或移动后,如何通过更改localhost连接为127.0.0.1来恢复MySQL连接。作者还提供了操作步骤和相关测试,展示了如何在不同情况下切换到TCP/IP连接方式。
摘要由CSDN通过智能技术生成

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值