mysql.sock的作用
註釋:
前段時間出現過一種情況,localhost本地登入mysql資料庫提示不能連線mysql.sock,第三方工具sqlyog可以登入,具體原因如下。
原創內容如下 mysql.sock的作用
mysql有兩種連線方式:
1、TCP/IP
2、socket
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> exit
Bye
[root@Wonhigh-Test16 ~]#
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 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 ~]# 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 ~]#
[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.
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 ~]#
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28602568/viewspace-1797619/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql執行報錯mysql.sockMySql
- Can'tconnecttolocalMySQLserverthroughsocket'/var/lib/mysql/mysql.sock'(2)MySqlServer
- error:'Can'tconnecttolocalMySQLserverthroughsocket'/var/lib/mysql/mysql.sock'(2)'ErrorMySqlServer
- Can't connect to local MySQL server through socket '/tmp/mysql.sock'MySqlServer
- js的作用域、作用域鏈JS
- 啟動mysql時顯示:/tmp/mysql.sock 不存在的解決方法MySql
- 解決不能透過mysql.sock連線MySQL問題的辦法(轉)MySql
- js的作用域和作用域鏈JS
- js的作用域與作用域鏈JS
- Java中的volatile的作用和synchronized作用Javasynchronized
- Symbol 的作用Symbol
- jQuery $ 的作用jQuery
- #include的作用
- Spring的作用域以及RequestContextListener作用SpringContext
- http 代理的作用HTTP
- JS的作用域JS
- Hashcode的作用
- Git分支的作用Git
- condition的作用
- 作用域的理解
- source命令的作用
- spring的作用Spring
- Oracle Undo的作用Oracle
- SMON 程式的作用
- __declspec(dllimport)的作用Import
- cookie的作用域Cookie
- SSH Agent 的作用
- noEmit 的作用是?MIT
- Kafka——zookeeper的作用Kafka
- ContentPresenter 的作用
- 解決Can 't connect to local MySQL server through socket '/tmp/mysql.sock '(2) "MySqlServer
- oracle的undo的作用Oracle
- Vue中key的作用Vue
- Symbol 的作用[翻譯]Symbol
- JAVA中initCause()的作用Java
- mock.js 的作用MockJS
- Token 的作用和原理
- 伺服器的作用伺服器