1. 程式人生 > >mysql.sock丟失後如何連接數據庫

mysql.sock丟失後如何連接數據庫

mysql sock丟失


防偽碼:沒有相當程度的孤獨是不可能有內心的平和。

【現象】

mysql.sock被刪除,導致無法連接數據庫。

[[email protected] ~]#mysql -uroot -p
Enter password:
ERROR 2002 (HY000): Can‘t connect to local MySQL server through socket ‘/tmp/mysql.sock‘ (2)

提示無法通過mysql.sock連接MySQL server。


解決

方案一:重啟數據庫會重新創建mysql.sock。

方案二:若暫時無法重啟數據庫,可以通過TCP協議連接數據庫。

MySQL默認使用的是UNIX套接字文件連接,而不是TCP/IP從。MySQL4.1開始,可以用--protocol=TCP|SOCKETPIPE|MEMORY指定選項連接數據庫。

[[email protected] ~]#mysql -uroot -p --protocol=TCP
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 16127
Server version: 5.6.36-log MySQL Community Server (GPL)
Copyright (c) 2000, 2017, 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>


本文出自 “簡明Linux” 博客,請務必保留此出處http://easylinux.blog.51cto.com/9732761/1948605

mysql.sock丟失後如何連接數據庫